日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > php >内容正文

php

微信登陆失败redirect_uri 域名与后台配置不一致 10003(thinkphp)

發布時間:2023/12/18 php 32 豆豆
生活随笔 收集整理的這篇文章主要介紹了 微信登陆失败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)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。