以前的文章是获取调用接口的一些基本参数,继续开发微信开放平台。数据库
public function tiaozhuan() { $info = getData('system_config', array('type' => 'pre_auth_code'), array(), 1); ////获取保存在数据库中的pre_auth_code $pre_auth_code = $info['value']; $back_url = "http://www.xxxxxx.com/index.php/$APPID$/callback"; //后台设置的回调地址,用户扫完二维码以后会跳转到这个链接 $url = 'https://mp.weixin.qq.com/cgi-bin/componentloginpage?component_appid=wxcda7bf3c4bf44cdc&pre_auth_code='.$pre_auth_code.'&redirect_uri='.$back_url; header("Location:".$url); }
//保存公众号信息 private function saveOpenWeixin() { //获取公众号access $info = getData('system_config', array('type' => 'component_access_token'), array() , 1); //获取保存在数据库中的component_access_token $component_access_token = $info['value']; $url = 'https://api.weixin.qq.com/cgi-bin/component/api_query_auth?component_access_token='.$component_access_token; $auth_code = $_GET['auth_code']; $post = array( 'component_appid' => $this->appid, //应用的appid 'authorization_code' => $auth_code, ); $ret=send_post($url, $post); $author = json_decode($ret, True); //获取公众号信息 $url = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token='.$component_access_token; $authorAppid = $author['authorization_info']['authorizer_appid']; $post = array( 'component_appid' => $this->appid, 'authorizer_appid' => $authorAppid, ); $ret = send_post($url, $post); $userInfo = json_decode($ret, True); //公众号信息 $authorInfo = $author['authorization_info']; }
//获取受权方的公众号账号基本信息 public function demo6() { $info = getData('system_config', array('type' => 'component_access_token'), array(), 1); //获取保存在数据库中的component_access_token $token = $info['value']; $url = 'https://api.weixin.qq.com/cgi-bin/component/api_get_authorizer_info?component_access_token='.$token; $post = array( 'component_appid' => $this->appid, 'authorizer_appid' => 'xxxxxxxxxx', //公众号appid ); $ret = send_post($url, $post); $res = json_decode($ret, True); } //微信帐号网页受权 public function demo8() { $appid = 'xxxx'; //公众号的appid $redirect = site_url('toupiao/'.$appid.'/callback'); //$scope = 'snsapi_base'; $scope = 'snsapi_userinfo'; //获取方式 $state = 'omllz'; $component_appid = $this->appid; //应用的appid $url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appid.'&redirect_uri='.$redirect.'&response_type=code&scope='.$scope.'&state='.$state.'&component_appid='.$component_appid.'#wechat_redirect'; header("Location:".$url); }
这是个人我的网站今日Tech 喜欢科技新闻的朋友能够收藏下。json