第一步:用户同意授权,获取code
成都创新互联长期为上千家客户提供的网站建设服务,团队从业经验10年,关注不同地域、不同群体,并针对不同对象提供差异化的产品和服务;打造开放共赢平台,与合作伙伴共同营造健康的互联网生态环境。为永安企业提供专业的网站设计制作、成都网站设计,永安网站改版等技术服务。拥有10余年丰富建站经验和众多成功案例,为您定制开发。在确保微信公众账号拥有授权作用域(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; }另外有需要云服务器可以了解下创新互联cdcxhl.cn,海内外云服务器15元起步,三天无理由+7*72小时售后在线,公司持有idc许可证,提供“云服务器、裸金属服务器、高防服务器、香港服务器、美国服务器、虚拟主机、免备案服务器”等云主机租用服务以及企业上云的综合解决方案,具有“安全稳定、简单易用、服务可用性高、性价比高”等特点与优势,专为企业上云打造定制,能够满足用户丰富、多元化的应用场景需求。