多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# checkSessionKey ### checkSessionKey 校验服务器所保存的登录态 `session_key` 是否合法。为了保持 `session_key` 私密性,接口不明文传输 `session_key`,而是通过校验登录态签名完成。 #### 请求地址 ``` <pre class="prettyprint"><ol class="linenums"><li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln">GET https</span><span class="pun">:</span><span class="com">//api.weixin.qq.com/wxa/checksession?access_token=ACCESS_TOKEN&signature=SIGNATURE&openid=OPENID&sig_method=SIG_METHOD</span></code></li></ol> ``` #### 参数 ##### string access\_token [接口调用凭证](/read/wechat-game-api/297.md) ##### string openid 用户唯一标识符 ##### string signature [用户登录态签名](https://developers.weixin.qq.com/minigame/dev/tutorial/open-ability/session-signature.html) ##### string sig\_method 用户登录态签名的哈希方法,目前只支持 hmac\_sha256 #### 返回值 ##### Object 返回的 JSON 数据包 属性类型说明支持版本errcodenumber错误码errmsgstring错误信息**errcode 的合法值** 值说明0ok 请求成功87009invalid signature 签名错误#### 调用示例 ``` <pre class="prettyprint"><ol class="linenums"><li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pln">curl </span><span class="pun">-</span><span class="pln">G </span><span class="str">'https://api.weixin.qq.com/wxa/checksession?access_token=OsAoOMw4niuuVbfSxxxxxxxxxxxxxxxxxxx&signature=fefce01bfba4670c85b228e6ca2b493c90971e7c442f54fc448662eb7cd72509&openid=oGZUI0egBJY1zhBYw2KhdUfwVJJE&sig_method=hmac_sha256'</span></code></li></ol> ``` #### 返回示例 正确时的返回JSON数据包如下: ``` <pre class="prettyprint"><ol class="linenums"><li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pun">{</span><span class="str">"errcode"</span><span class="pun">:</span><span class="pln"> </span><span class="lit">0</span><span class="pun">,</span><span class="pln"> </span><span class="str">"errmsg"</span><span class="pun">:</span><span class="pln"> </span><span class="str">"ok"</span><span class="pun">}</span></code></li></ol> ``` 错误时的返回JSON数据包如下(示例为签名错误): ``` <pre class="prettyprint"><ol class="linenums"><li class="l"><code class="pcalibre9 pcalibre8 pcalibre7"><span class="pun">{</span><span class="str">"errcode"</span><span class="pun">:</span><span class="pln"> </span><span class="lit">87009</span><span class="pun">,</span><span class="pln"> </span><span class="str">"errmsg"</span><span class="pun">:</span><span class="pln"> </span><span class="str">"invalid signature"</span><span class="pun">}</span></code></li></ol> ``` > 原文: <https://developers.weixin.qq.com/minigame/dev/api/open-api/login/checkSessionKey.html>