<?php /* 本文件位置 $redirect_url= "http://israel.duapp.com/weixin/oauth2_openid.php"; URL https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx6292681b13329528&redirect_uri=http://israel.duapp.com/weixin/oauth2_openid.php&response_type=code&scope=snsapi_base&state=1#wechat_redirect */ $code = $_GET["code"]; //$userinfo = getUserInfo($code); $openid = getUserId($code); $deviceid = getDeviceId($openid); $deviceList = getDeviceList($deviceid); function getUserId($code) { $appid = "wx250d00817156085c"; $appsecret = "50c6b69c831f811d4d723990abec6173"; //oauth2的方式获得openid $access_token_url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid={$appid}&secret={$appsecret}&code={$code}&grant_type=authorization_code"; $access_token_json = https_request($access_token_url); $access_token_array = json_decode($access_token_json, true); $openid = $access_token_array['openid']; return $openid; } function getDeviceId($openid) { $appid = "wx250d00817156085c"; $appsecret = "50c6b69c831f811d4d723990abec6173"; //非oauth2的方式获得全局access token $new_access_token_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={$appid}&secret={$appsecret}";
{ if (is_string($sch)) { $days = explode(":", $sch); foreach ($days as $day) { $result = doPost($deviceId, "receiveSch", $day); if ($result != "Success") { break; } } return $result; } else { return "Invalid schedule"; } } $deviceName = filter_input(INPUT_GET, "deviceName", FILTER_SANITIZE_STRING); $deviceId = getDeviceId($deviceName); if ($deviceId === false) { $result = "Invalid device {$deviceName}"; } else { $cmd = filter_input(INPUT_GET, "cmd", FILTER_SANITIZE_STRING); switch ($cmd) { case "status": case "schedule": case "config": $result = doGet($deviceId, $cmd); break; case "receiveSch": $sch = filter_input(INPUT_POST, "params", FILTER_SANITIZE_STRING); $result = doSchedule($deviceId, $sch); break; case "sendMsg":