public function authorize($authorize_url, $client_id, $redirect_uri, $scope = "user", $client_secret, $uri, $uri_token, $homepage) { $req = new oauth2(); $req->request($authorize_url, $client_id, $redirect_uri, $scope); $req->authorize($client_id, $client_secret, $redirect_uri, $uri, $uri_token); $req->back($homepage); }
/** * @param $id 接口 查询商业id * @return mixed */ public function search_business_id($id) { $config = array('prism' => array('key' => 'AQAFY1', 'secret' => '3JD5ZICVHKMAT5EOAY6A', 'site' => 'https://openapi.ishopex.cn', 'oauth' => 'https://oauth.ishopex.cn')); //关于新用户中心调用查看的接口方法 //测试环境可能有时间差!所以通过网络获取 //$snoopy = new Snoopy(); //$snoopy->submit("http://openapi.ishopex.cn/api/platform/timestamp",""); //$time = $snoopy->results; $time = time(); $url = 'api/usercenter/passport/getinfo'; //echo date("Y-m-d H:i:s",$time); //$data["uid"] = '441111082500'; //$data["login_name"] = "*****@*****.**"; $data["login_name"] = $id; $prism = new oauth2($config['prism']); //echo "<pre>";print_r($prism);print_r($data);//exit; $r = $prism->request()->post($url, $data, $time); //exit; //print_r($r);exit; $res = $r->parsed(); return $res; }
<?php /** *授权获取用户信息。包括头像、昵称 */ error_reporting(E_ALL & ~E_NOTICE); include './oauth2.php'; $code = $_GET['code']; //code 微信接口参数(必须) $state = $_GET['state']; //state微信接口参数(不需传参则不用);若传参可考虑规则: 'act'.'arg1'.'add'.'arg2' $APPID = ''; $SECRET = ''; $REDIRECT_URL = ''; //当前页面地址 $oauth2 = new oauth2(); $oauth2->init($APPID, $SECRET, $REDIRECT_URL); if (empty($code)) { $oauth2->get_code_by_authorize($state); //获取code,会重定向到当前页。若需传参,使用$state变量传参。 } $data = $oauth2->get_userinfo_by_authorize(); echo '</br>welcome test!'; echo '</br>nickname: ' . $data['nickname']; echo '</br>headimgurl: ' . $data['headimgurl'];
<?php /** * 获取用户openid */ error_reporting(E_ALL & ~E_NOTICE); include './oauth2.php'; $code = $_GET['code']; //code 微信接口参数(必须) $state = $_GET['state']; //state微信接口参数(不需传参则不用);若传参可考虑规则: 'act'.'arg1'.'add'.'arg2' $APPID = ''; $SECRET = ''; $REDIRECT_URL = ''; //当前页面地址 $oauth2 = new oauth2(); $oauth2->init($APPID, $SECRET, $REDIRECT_URL); if (empty($code)) { $oauth2->get_code($state); //获取code,会重定向到当前页。若需传参,使用$state变量传参。 } $openid = $oauth2->get_openid(); //获取openid echo '</br>welcome test!'; echo '</br>code: ' . $code; echo '</br>openid: ' . $openid;
function __construct($config, $token) { parent::__construct($config); $this->__token = $token; }