求解,uniapppost请求 后端拿到的值为空 请大家看一看
问题相关代码,请勿粘贴截图
前端的代码
getUserOpenId(userInfo){
var that = this
uni.login({
provider:‘weixin’,
success(loginAuth) {
var code = {‘code’:loginAuth.code};
console.log(code);
var path = ‘http://localhost:8080/User/getUserInfo’;
uni.request({
header: {‘content-type’: ‘application/json;charset:utf-8’ },
url:path,
method:“POST”,
data:{code},
success:(res)=> {
that.openid=res.data.openid,
that.session_key=res.data.session_key,
console.log(openid),
console.log(session_key)
}
})
后端的代码 appid和session_key去掉了(隐私哈哈)
@Override
public String getUserOpenId(String code) {
System.out.println(code);
String authUrl = “https://api.weixin.qq.com/sns/jscode2session?appid=&secret=&grant_type=authorization_code”;
authUrl = authUrl + “&js_code” + code;
String result = HttpUtil.get(authUrl);
System.out.println(result);
JSONObject JSONObject = JSONUtil.parseObj(result);
String openId = JSONObject.getStr(“openid”);
String sessionKey = JSONObject.getStr(“session_key”);
return result;
}
运行结果及报错内容
然后后端提示
null
{“errcode”:41008,“errmsg”:“missing code, rid: 62c50911-1a062cff-10ded153”}
拿不到前端的code