国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > PHP > 正文

PHP實(shí)現(xiàn)微信網(wǎng)頁授權(quán)開發(fā)教程

2020-03-22 20:31:00
字體:
供稿:網(wǎng)友
微信網(wǎng)頁授權(quán)是服務(wù)號才有的高級功能,開發(fā)者可以通過授權(quán)后獲取用戶的基本信息;在此之前,想要獲取消息信息只能在用戶和公眾號交互時根據(jù)openid獲取用戶信息;而微信網(wǎng)頁授權(quán)可在不需要消息交互,也不需要關(guān)注的情況下獲取用戶的基本信息。微信網(wǎng)頁授權(quán)時通過OAuth2.0完成的,整個過程分為三步:
用戶授權(quán),獲取code; 根據(jù)code獲取access_token【可通過refresh_token刷新獲取較長有效期】 通過access_token和openid獲取用戶信息

$redirect_uri = urlencode($redirect_uri); return "https://open.weixin.qq.com/connect/oauth2/authorize appid={$this- app_id}&redirect_uri={$redirect_uri}&response_type=code&scope=snsapi_userinfo&state={$state}#wechat_redirect"; * 獲取授權(quán)token * @param string $code 通過get_authorize_url獲取到的code html' target='_blank'>public function get_access_token($app_id = '', $app_secret = '', $code = '') $token_url = "https://api.weixin.qq.com/sns/oauth2/access_token appid={$this- app_id}&secret={$this- app_secret}&code={$code}&grant_type=authorization_code"; $token_data = $this- http($token_url); if($token_data[0] == 200) return json_decode($token_data[1], TRUE); return FALSE; * 獲取授權(quán)后的微信用戶信息 * @param string $access_token * @param string $open_id public function get_user_info($access_token = '', $open_id = '') if($access_token && $open_id) $info_url = "https://api.weixin.qq.com/sns/userinfo access_token={$access_token}&openid={$open_id}&lang=zh_CN"; $info_data = $this- http($info_url); if($info_data[0] == 200) return json_decode($info_data[1], TRUE); return FALSE; public function http($url, $method, $postfields = null, $headers = array(), $debug = false) $ci = curl_init(); /* Curl settings */ curl_setopt($ci, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1); curl_setopt($ci, CURLOPT_CONNECTTIMEOUT, 30); curl_setopt($ci, CURLOPT_TIMEOUT, 30); curl_setopt($ci, CURLOPT_RETURNTRANSFER, true); switch ($method) { case 'POST': curl_setopt($ci, CURLOPT_POST, true); if (!empty($postfields)) { curl_setopt($ci, CURLOPT_POSTFIELDS, $postfields); $this- postdata = $postfields; break; curl_setopt($ci, CURLOPT_URL, $url); curl_setopt($ci, CURLOPT_HTTPHEADER, $headers); curl_setopt($ci, CURLINFO_HEADER_OUT, true); $response = curl_exec($ci); $http_code = curl_getinfo($ci, CURLINFO_HTTP_CODE); if ($debug) { echo "=====post data======/r/n"; var_dump($postfields); echo '=====info=====' . "/r/n"; print_r(curl_getinfo($ci)); echo '=====$response=====' . "/r/n"; print_r($response); curl_close($ci); return array($http_code, $response);}以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助。PHP教程

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請第一時間聯(lián)系我們修改或刪除,多謝。

發(fā)表評論 共有條評論
用戶名: 密碼:
驗(yàn)證碼: 匿名發(fā)表
主站蜘蛛池模板: 昌宁县| 临澧县| 太湖县| 佳木斯市| 讷河市| 桐柏县| 内黄县| 潮安县| 潜山县| 英山县| 合水县| 五河县| 衡水市| 沁源县| 湘潭市| 东光县| 萝北县| 来安县| 阿勒泰市| 靖州| 乐业县| 太仆寺旗| 嘉荫县| 平江县| 勃利县| 申扎县| 德格县| 靖州| 深泽县| 崇义县| 盘锦市| 郸城县| 得荣县| 乐昌市| 扶风县| 武功县| 清水河县| 两当县| 九台市| 邻水| 临安市|