微信登陆失败redirect_uri 域名与后台配置不一致 10003(thinkphp)
public function index(){
$redirect_url = 'http://www.ceshi.com/ceshi';//設置域名時沒有http://,在獲取code時必須有,否則將一直顯示10003錯誤
$a = $this->baseAuth($redirect_url);
}
//設置網絡請求配置
public function _request($curl,$https=true,$method='GET',$data=null){
// 創建一個新cURL資源
$ch = curl_init();
// 設置URL和相應的選項
curl_setopt($ch, CURLOPT_URL, $curl); //要訪問的網站
curl_setopt($ch, CURLOPT_HEADER, false); //啟用時會將頭文件的信息作為數據流輸出。
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); //將curl_exec()獲取的信息以字符串返回,而不是直接輸出。
if($https){
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //FALSE 禁止 cURL 驗證對等證書(peer's certificate)。
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, true); //驗證主機
}
if($method == 'POST'){
curl_setopt($ch, CURLOPT_POST, true); //發送 POST 請求
curl_setopt($ch, CURLOPT_POSTFIELDS, $data); //全部數據使用HTTP協議中的 "POST" 操作來發送。
}
// 抓取URL并把它傳遞給瀏覽器
$content = curl_exec($ch);
if ($content === false) {
return "網絡請求出錯: " . curl_error($ch);
exit();
}
//關閉cURL資源,并且釋放系統資源
curl_close($ch);
return $content;
}
/**
* 獲取用戶的openid
*/
public function baseAuth($redirect_url){
//1.準備scope為snsapi_base網頁授權頁面
$baseurl = urlencode($redirect_url);
//公眾號
$appid = '***********';//填寫自己的appid
$appsecret = '***************';//填寫自己的appsecret
$snsapi_base_url = 'https://open.weixin.qq.com/connect/oauth2/authorize?appid='.$appid.'&redirect_uri='.$baseurl.'&response_type=code&scope=snsapi_base&state=YQJ#wechat_redirect';
//2.靜默授權,獲取code
//頁面跳轉至redirect_uri/?code=CODE&state=STATE
$code = $_GET['code'];
if( !isset($code) ){
header('Location:'.$snsapi_base_url);
}
//3.通過code換取網頁授權access_token和openid
$curl = 'https://api.weixin.qq.com/sns/oauth2/access_token?appid='.$appid.'&secret='.$appsecret.'&code='.$code.'&grant_type=authorization_code';
$content = $this->_request($curl);
$result = json_decode($content,true);
return $result;
}
總結
以上是生活随笔為你收集整理的微信登陆失败redirect_uri 域名与后台配置不一致 10003(thinkphp)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python调用高德地图地理编码/逆地理
- 下一篇: echart表格颜色设置