微信服務網頁,想獲得關注者的openid
用
https://api.weixin.qq.com/sns/oauth2/access_token?appid=wxb6692daa2a19194&appsecret=1808e9ce5acb4c7f2838e8edcfd0a6a
總是報錯
{"errcode":41004,"errmsg":"appsecret missing, hints: [ req_id: 8v6gIa0320th20 ]"}
可是傳了appsecret
uj5u.com熱心網友回復:
public function getBaseInfo()
{
\Think\Log::record("PublicController:getBaseInfo called", "DEBUG");
//1、獲取code
$appid = C('APPID');
$redirect_url = urlencode(C('SERVER_ADDR').'/index.php/Weixin/Public/getUserOpenId');
$url = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=".$redirect_url."&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
header('location:'.$url);
exit();
}
//獲取用戶openid
public function getUserOpenId()
{
\Think\Log::record("PublicController:getUserOpenId called", "DEBUG");
$appid = C('APPID');
$appsecret = C('APPSECRET');
$code = $_GET['code']; //從上面函式getBaseInfo獲取得到
$url = "https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$appsecret."&code=".$code."&grant_type=authorization_code ";
//3、獲取openid
$res = json_decode(httpGet($url));
$unionId = WxAccessTokenController::getInstance()->getGZHUnionid($res->openid);
$this->assign('unionId', $unionId);
$this->display('login');
}
以上是我的代碼,你應該參考靜默授權,先獲取code,通過code在獲取openid
uj5u.com熱心網友回復:
appsecret錯誤,是你的appsecret有問題uj5u.com熱心網友回復:
很明顯是 appsecret的問題,但是這種情況,往往是在開發代碼的時候,代碼運行邏輯中對appsecret有過處理,很弱很弱的一個粗心造成的。往往找到問題后回恍然大悟。使用分層排除法,是常用的解決方案。1.判斷最表面層,appsecret是否正確或是帶了亂碼或是什么
2.下載微信官方DEMO進行驗證,網路傳輸,密鑰等資訊是否正確。若官方DEMO沒有問題。說明肯定是你的開發語言不兼容或代碼問題
3.小程式,小游戲討論Q69-3593-325
判斷錯誤,可以分層進行排除判斷是一種常用方法
uj5u.com熱心網友回復:
這一頓分析看笑了,這不是引數名寫錯了么?應該是secret而不是appsecret轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/100008.html
標籤:微信開發
上一篇:【2020CCPC網路賽】1005 Lunch(HDU6892)
下一篇:求救啊
