Beispiel #1
0
 /**
  * 第二步:通过code换取网页授权access_token 得到openid 并存入session
  * @param $code
  * @param redirect_uri 回调地址
  */
 public function getOpenid($code, $redirect_uri)
 {
     $url = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid=' . $this->appid . '&secret=' . $this->appsecret . '&code=' . $code . '&grant_type=authorization_code';
     $data = httpsRequest($url);
     $data = json_decode($data, true);
     if (isset($data['errcode']) && $data['errcode'] == '40029') {
         $this->getcode($redirect_uri);
     }
     $openid = $data['openid'];
     $_SESSION['openid'] = $openid;
 }
 /**
  * 设置微信菜单
  *
  */
 public function setMenu()
 {
     /*获取access_token*/
     $access_token = getAccessToken();
     $url_seller = U('Weixin/Index/jump?destination=seller', '', '', TRUE);
     $url_buyer = U('Weixin/Index/jump?destination=buyer', '', '', TRUE);
     $url_order = U('Weixin/Index/jump?destination=order', '', '', TRUE);
     $url_income = U('Weixin/Index/jump?destination=income', '', '', TRUE);
     $url_sale = U('Weixin/Index/jump?destination=sale', '', '', TRUE);
     $url_agent = U('Weixin/Index/jump?destination=agent', '', '', TRUE);
     $url_teach = U('Weixin/Index/jump?destination=teach', '', '', TRUE);
     $menu = '{
       "button":[
       {
            "name":"我要开店",
            "sub_button":[
             {
                "type":"view",
                "name":"开店指导",
                "url":"' . $url_teach . '"
             },
             {
                "type":"view",
                "name":"我的微店",
                "url":"' . $url_buyer . '"
             },
             {
                "type":"view",
                "name":"注册与编辑",
                "url":"' . $url_seller . '"
             }]
       
 
        }],
       "button":[
       {
            "name":"我",
            "sub_button":[
             {
                "type":"view",
                "name":"我的代理",
                "url":"' . $url_agent . '"
             },
             {
                "type":"click",
                "name":"我的维权",
                "key":"天气北京"
             },
             {
                "type":"view",
                "name":"我的收入",
                "url":"' . $url_income . '"
             },
             {
                "type":"view",
                "name":"销售管理",
                "url":"' . $url_sale . '"
             },
             {
                "type":"view",
                "name":"订单管理",
                "url":"' . $url_order . '"
             }]
       
 
        }],
       "button":[
       {
            "name":"平台中心",
            "sub_button":[
             {
                "type":"click",
                "name":"平台优势",
                "key":"天气北京"
             },
             {
                "type":"click",
                "name":"平台理念",
                "key":"天气上海"
             }]
       
 
        }],
        
     }';
     $url = "https://api.weixin.qq.com/cgi-bin/menu/create?access_token=" . $access_token;
     $result = httpsRequest($url, $menu);
     var_dump($result);
 }