您好,登錄后才能下訂單哦!
第一步:用戶同意授權,獲取code
在確保微信公眾賬號擁有授權作用域(scope參數)的權限的前提下(服務號獲得高級接口后,默認帶有scope參數中的snsapi_base和snsapi_userinfo),引導關注者打開如下頁面:
https://open.weixin.qq.com/connect/oauth3/authorize?appid=APPID&redirect_uri=REDIRECT_URI&response_type=code&scope=SCOPE&state=STATE#wechat_redirect
所以
先用調試接口生成自定義菜單,菜單json如下:
{
"button":[
{
"name":"風信科技",
"sub_button":[
{
"type":"click",
"name":"關于風信",
"key":"FS_V1_1001"
},
{
"type":"click",
"name":"我們的服務",
"key":"FS_V1_1002"
},
{
"type":"click",
"name":"成功案例",
"key":"FS_V1_1003"
},
{
"type":"click",
"name":"解決方案",
"key":"FS_V1_1004"
},
{
"type":"click",
"name":"OA通訊錄",
"key":"FS_V1_1005"
}]
},
{
"name":"風信產品",
"sub_button":[
{
"type":"click",
"name":"平臺產品",
"key":"FS_V2_1001"
},
{
"type":"click",
"name":"領域產品",
"key":"FS_V2_1002"
},
{
"type":"click",
"name":"行業產品",
"key":"FS_V2_1003"
},
{
"type":"view",
"name":"微辦公",
"url":"https://open.weixin.qq.com/connect/oauth3/authorize?appid=$APPID&redirect_uri=$URL&response_type=code&scope=snsapi_base&state=1#wechat_redirect"
}]
},
{
"name":"風信娛樂",
"sub_button":[
{
"type":"click",
"name":"抽獎活動",
"key":"FS_V3_1001"
},
{
"type":"click",
"name":"查詢天氣",
"key":"FS_V3_1002"
},
{
"type":"view",
"name":"更多活動",
"url":"http://www.funsing.com/"
}]
}]
}
第二步,獲取openId,
public function index() { $code = I('get.code'); $weid = $this->getOpenId($code); if ($weid == "") { $this->redirect('/Home/Index/login', array(), 0, "waiting..."); } else { $result = json_decode($this->client->IsAccount(array("weId"=>$weid))->IsAccountResult); $info = $result->ErrMsg; $this->gotoPage($info, $weid); } }
//通過code取得openid public function getOpenId($code) { $urlpre = "https://api.weixin.qq.com/sns/oauth3/access_token?appid=".$this->appId."&secret=".$this->appsecret."&grant_type=authorization_code&code="; $url = $urlpre.$code; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $jsoninfo = json_decode($output, true); //$access_token = $jsoninfo["access_token"]; $openid = $jsoninfo["openid"]; return $openid; }
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。