function ydwx_refresh_access_token($appid, $appsecret) { $http = new YDHttp(); $msg = $http->get(YDWX_WEIXIN_BASE_URL . "token?grant_type=client_credential&appid=" . $appid . "&secret=" . $appsecret); $accessToken = new YDWXAccessTokenResponse($msg); if ($accessToken->isSuccess()) { return $accessToken; } throw new YDWXException($accessToken->errmsg, $accessToken->errcode); }
/** * 获取第三方平台access_token * * @param unknown $verify_ticket 是微信没10分钟推送得到,需要注册hook * @throws YDWXException * @return YDWXAccessTokenResponse */ function ydwx_agent_access_token($verify_ticket) { $http = new YDHttp(); $info = $http->post(YDWX_WEIXIN_BASE_URL . "component/api_component_token", ydwx_json_encode(array("component_appid" => YDWX_WEIXIN_COMPONENT_APP_ID, "component_appsecret" => YDWX_WEIXIN_COMPONENT_APP_SECRET, "component_verify_ticket" => $verify_ticket))); $msg = new YDWXAccessTokenResponse($info); $msg->access_token = $msg->component_access_token; if ($msg->isSuccess()) { return $msg; } throw new YDWXException($msg->errmsg); }