storage.setUserStorage “errcode":87009 "errmsg":"invalid signature

    try{
            $method = 'hmac_sha256';

            $access_token = $this->getAccessToken();

            $item = [];
            $item['value'] = $level;
            $item['key'] = self::USER_LEVEL_KEY;

            $body = [];
            $body['kv_list'][] = $item;


            $signature = hash_hmac('sha256', json_encode($body), $session_key);

            $url = "https://api.weixin.qq.com/wxa/set_user_storage?access_token={$access_token}&signature={$signature}&openid={$open_id}&sig_method={$method}";

            $result = $this->curl_post_request($url, $body);

    
            if(empty($result['errcode'])){
                return TRUE;
            }else{
                throw new PadException(RespCode::BAN_SIGNUP, json_encode($result));
            }
        }catch (Exception $e){
            MWlog::debug('Upload Fail :' . $open_id);
        }

注意: 只有 kv_list 参与签名, 签名的key值是微信登录jscode2session接口的返回值 session_key。

转载自:https://developers.weixin.qq.com/community/develop/doc/0008caa0780478fd47c6abd0e55c00?_at=1571915090408

posted @ 2019-10-24 19:11  GoodByeZ  阅读(619)  评论(0编辑  收藏  举报