我通过公众号调用此接口返回serviceid错误,post和res数据如下:
POST:{"service":"wxd8a88093cf541a77","api":"weopensecriskservice","data":{"openid":"omY2AwaS9BgyNi8QnNmHdrVrqbW4","serviceid":3,"user_access_token":"48_Yy_QqETRSDVaidMqFKbyW5aMx182io7DujcacQsIIqaZ5NmGe5tPovTBM4SjZBMeh5zU2wFly1lo5JmkwjP8Ww"},"client_msg_id":"top20210909161036"}
RES:{"errcode":0,"errmsg":"ok","data":"{\"code\":9,\"msg\":\"serviceid参数错误!\"}","request_id":"MLws4YDUZNgxqgL7aDLku6-qUuIs6wD-WTRM9Qr97aUpoCP-DxEE2tvx55n6o9dC9vg","provider_errmsg":""}
然后我又试了下小程序调用,结果又返回serviceid错误,post和res数据如下:
POST:{"service":"wxd8a88093cf541a77","api":"weopensecriskservice","data":{"openid":"o0wn_0N-ourfcf-09BopNPmq0EYs","serviceid":3},"client_msg_id":"client_msg_id_wxd8a88093cf541a77"}
RES:{"errcode":0,"errmsg":"ok","data":"{\"code\":9,\"msg\":\"serviceid参数错误!\"}","request_id":"MLwviQaHhN5_SGXv-KVntYh9nKhE7H_Udw4vjhLd5_7OmEbuDoWI6R6rAwj-XVa2rwQ","provider_errmsg":""}
这个serviceid难道不是固定的3吗?还是哪的问题?
可以看下下面这段代码
# -*- coding: utf-8 -*- import requests import json def getaccess_token(appid, secret): getAccessTokenUrl = 'https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid={0}&secret={1}'.format(appid, secret) getAccessTokenReq = requests.get(getAccessTokenUrl) getAccessTokenReqContent = json.loads(getAccessTokenReq.text) access_token = getAccessTokenReqContent['access_token'] return access_token def getrisk(appid, secret, openid): # 获取开放者票据 access_token = getaccess_token(appid, secret) # 请求营销反作弊接口 url = 'https://api.weixin.qq.com/wxa/servicemarket?access_token={0}'.format(access_token) data = json.dumps({ "service": "wxd8a88093cf541a77", "api": "weopensecriskservice", "data": { "openid": openid, "serviceid": 3, "sale_risk": { "mchcode": "xx", # 非必须,可以空字符串 "phonenum": "xx", # 非必须,可以空字符串 "certid": "xx", # 非必须,可以空字符串 "wifibssid": "xx", # 非必须,可以空字符串 "clientip": "xx", # 非必须,可以空字符串 "deviceid": "xx" # 非必须,可以空字符串 } # sale_risk结构不能缺失 }, "client_msg_id": "client_msg_id_weopensecriskservice" # 固定标识 }) session = requests.Session() req = session.post(url, data) reqcontent = req.text return reqcontent if __name__ == '__main__': appid = 'xxx' secret = 'xxx' openid = 'xxx' res = getrisk(appid, secret, openid) print(res)