0
点赞
收藏
分享

微信扫一扫

微信小程序电话解密

捌柒陆壹 2022-05-06 阅读 82
@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;
}
举报

相关推荐

0 条评论