@Override public String authLogin(WXAuth wxAuth) throws Exception { String url = "https://api.weixin.qq.com/sns/jscode2session?appid={0}&secret={1}&js_code={2}&grant_type=authorization_code"; String replaceUrl = url.replace("{0}", appid).replace("{1}", secret).replace("{2}", wxAuth.getCode()); String res = HttpClientUtil.sendGetRequest(replaceUrl,"UTF-8"); log.info("发送链接后获得的数据{}",res); JSONObject jsonObject = JSON.parseObject(res); String sessionKey = (String) jsonObject.get("session_key"); String wxRes= WXUtil.wxDecrypt(wxAuth.getEncryptedData(),sessionKey,wxAuth.getIv()); log.info("解密后获得的数据{}",wxRes); JSONObject json = JSON.parseObject(wxRes); String phoneNumber = (String) json.get("phoneNumber"); return phoneNumber; }
package com.mes.metering.param; import lombok.Data; import lombok.experimental.Accessors; /** * @Author * @Date: 2021-09-14 16:42 * version 1.0 */ @Data @Accessors(chain = true) public class WXAuth { private String encryptedData; private String iv; // private String session_key; private String code; }
weixin.appid=wx47c97b2f6850072a1111 weixin.secret=11112f8a1d10d5db394845f6c27ae0c047de