小程序
小游戏
企业微信
微信支付
扫描小程序码分享
wx.login获取openId一定要把appid那些参数写在https://api.weixin.qq.com/sns/jscode2session里面?
4 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
楼主我想资讯下,我在本地通过后台方法拿到appid了。提交体验版时就获取不到,这个是什么原因。是因为我们的服务器访问不了外网么
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.ystlfj.oa.config.weixin.WeiXinConfig; import com.ystlfj.oa.pojo.WeiXinLogin; import com.ystlfj.oa.service.WeiXinLoginService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import java.io.IOException; @Service("weiXinLoginService") public class WeiXinLoginServiceImpl implements WeiXinLoginService { @Autowired private WeiXinConfig weiXinConfig; private static Logger logger = LoggerFactory.getLogger(WeiXinLoginServiceImpl.class); @Override public WeiXinLogin getOpenId(String code) { String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + weiXinConfig.getAppid() + "&secret=" + weiXinConfig.getSecret() + "&js_code=" + code + "&grant_type=authorization_code"; RestTemplate template = new RestTemplate(); String result = template.getForObject(url,String.class); ObjectMapper mapper = new ObjectMapper(); WeiXinLogin weiXinLogin =new WeiXinLogin(); try { // 将相关key对应的value里的的string转换成对象的实体类集合 weiXinLogin = mapper.readValue(result, WeiXinLogin.class); } catch (JsonParseException e) { e.printStackTrace(); logger.error(e.getMessage()); } catch (JsonMappingException e) { e.printStackTrace(); logger.error(e.getMessage()); } catch (IOException e) { e.printStackTrace(); logger.error(e.getMessage()); } // System.out.println(url); // System.out.println(result); // System.out.println(weiXinLogin.toString()); return weiXinLogin; } } springboot2.1.6 用的 RestTemplate 发起http连接,weixinconfig 是 配置类获取 appid 和 secret, WeiXinLogin 封装 获取到 openid 和session_key
谢邀,直接拼,就OK。APPID和秘钥我都弄的假的。
是的
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
楼主我想资讯下,我在本地通过后台方法拿到appid了。提交体验版时就获取不到,这个是什么原因。是因为我们的服务器访问不了外网么
import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; import com.ystlfj.oa.config.weixin.WeiXinConfig; import com.ystlfj.oa.pojo.WeiXinLogin; import com.ystlfj.oa.service.WeiXinLoginService; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.web.client.RestTemplate; import java.io.IOException; @Service("weiXinLoginService") public class WeiXinLoginServiceImpl implements WeiXinLoginService { @Autowired private WeiXinConfig weiXinConfig; private static Logger logger = LoggerFactory.getLogger(WeiXinLoginServiceImpl.class); @Override public WeiXinLogin getOpenId(String code) { String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + weiXinConfig.getAppid() + "&secret=" + weiXinConfig.getSecret() + "&js_code=" + code + "&grant_type=authorization_code"; RestTemplate template = new RestTemplate(); String result = template.getForObject(url,String.class); ObjectMapper mapper = new ObjectMapper(); WeiXinLogin weiXinLogin =new WeiXinLogin(); try { // 将相关key对应的value里的的string转换成对象的实体类集合 weiXinLogin = mapper.readValue(result, WeiXinLogin.class); } catch (JsonParseException e) { e.printStackTrace(); logger.error(e.getMessage()); } catch (JsonMappingException e) { e.printStackTrace(); logger.error(e.getMessage()); } catch (IOException e) { e.printStackTrace(); logger.error(e.getMessage()); } // System.out.println(url); // System.out.println(result); // System.out.println(weiXinLogin.toString()); return weiXinLogin; } } springboot2.1.6 用的 RestTemplate 发起http连接,weixinconfig 是 配置类获取 appid 和 secret, WeiXinLogin 封装 获取到 openid 和session_key
谢邀,直接拼,就OK。APPID和秘钥我都弄的假的。
是的