- wx.login请求服务器返回数据data: "null[B@c35210c"是openid吗?
小程序端代码: wx.login({ success: res => { if (res.code) { //let URL = 'https://api.weixin.qq.com/sns/jscode2session?appid=aaaaaaaa&secret=aaaaaaaaaaaaaaaa&js_code='+res.code+'&grant_type=authorization_code' // 这个url在服务器端代码调用 //http://10.221.129.198:8080/request?type=100 let URL = 'http://10.221.129.198:8080/request?login_code='+res.code console.log(URL) wx.request({ url: URL , timeout: 100000, success:function(res){ //res.data中有openid console.log(res) console.log('login request success') fail: function (res) { console.log(res) console.log('login request failed') fail: function (res) { console.log('login failed') console.log(res) 服务器端代码: @Controller public class ServerController { @RequestMapping(value = "/request") public @ResponseBody String request(@RequestParam(value="login_code") String code) { String res = null; if ( !code.equals(' ') ) { // 向微信申请获取用户id信息 // https://api.weixin.qq.com/sns/jscode2session? // appid=aaaaaaaaaaaaaaaa&secret=aaaaaaaaaaaaaaaa // js_code=code // &grant_type=authorization_code String str_url = "https://api.weixin.qq.com/sns/jscode2session?appid=aaaaaaaaaaaaa&secret=bbbbbbbbbbbbbb&js_code='+code+'&grant_type=authorization_code"; InputStream in = null; OutputStream out = null; try { URL url = new URL(str_url); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestProperty("User-Agent","Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)"); in = new BufferedInputStream(connection.getInputStream()); out = new BufferedOutputStream(new FileOutputStream("/home/lys/package-app-NewHomeService/login.txt", true)); byte[] bytes = new byte[1024]; int len = 0; if((len = in.read(bytes)) != -1) { res = bytes.toString(); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); // HttpServletRequest request = null; // HttpServletResponse response = null; } else { res = "request value error!"; return res; 小程序端返回的res最后打印出来的数据:和服务器端断点看到的url返回值一样 {data: "null[B@c35210c", header: {…}, statusCode: 200, cookies: Array(0), errMsg: "request:ok"}cookies: [] data: "null[B@c35210c" errMsg: "request:ok" header: Connection: "keep-alive"Content-Length: "14"Content-Type: "text/plain;charset=UTF-8"Date: "Thu, 23 Feb 2023 09:39:00 GMT"Keep-Alive: "timeout=60" __proto__: ObjectstatusCode: 200__proto__: Object login request success login调用期间,小程序没用弹出确认登陆的弹窗,感觉很奇怪 请问下各位login成功的同学们,你们返回值是这样的吗
2023-02-23 - 配置服务器域名时候,request合法域名,不允许配置本地服务器的ip网址,大家如何处理?
个人小程序,开发中未上线,需要在服务器端使用api,需要使用数据库。请问下,后端服务是本地台式机在idea搭建的服务器,要怎么配置呢。小程序配置服务器域名时候,request合法域名那一项,不允许配置本地服务器的ip网址。请问下,大家都是购买了云服务和域名和DNS解析服务且域名备案了吗
2023-02-23