問題原因
1、授權碼(auth_code)的appid設置錯誤
2、授權碼(auth_code) 錯誤
3、授權碼(auth_code)已被使用
4、授權碼(auth_code) 過期
5、授權碼(auth_code)狀態錯誤,授權方式和接口不對應
解決方案
1、授權碼(auth_code)的appid設置錯誤
請確認是否使用錯誤的appid獲取code,授權碼(auth_code)必須是獲取用戶信息的商戶進行調用。
(1)如果是自調用模式,拼接授權鏈接的appid或者綁定小程序的appid必須與調用接口的appid一致。
(2)如果是三方調用模式(服務商代商戶獲取用戶信息),在用戶信息授權鏈接中appid必須設置為授權商戶的appid,而不是服務商的appid。
2、授權碼(auth_code) 錯誤
請確定傳入的auth_code是否拼寫錯誤,或未設置。
3、授權碼(auth_code)已被使用
auth_code為1次有效,不可重復使用,請確定傳入的auth_code是否已經被使用過。
4、授權碼(auth_code) 過期
auth_code有效期最久24小時,請確定傳入的auth_code是否因為長時間未使用,已經過期。
5、授權碼(auth_code)狀態錯誤
請確認獲取auth_code的拼接鏈接是否正確,用戶信息授權拼接示例如下:
https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=APPID&scope=SCOPE&redirect_uri=ENCODED_URL
具體請參考換取授權訪問令牌(alipay.system.oauth.token)接口文檔。
參考鏈接
https://opendocs.alipay.com/support/01rg6z
https://opendocs.alipay.com/apis/api_9/alipay.system.oauth.token