极光一键登录 -获取手机号码

package com.jzbox.util;

import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpRequest;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jzbox.exception.BizException;
import lombok.extern.slf4j.Slf4j;
import javax.crypto.Cipher;
import java.security.KeyFactory;
import java.security.PrivateKey;
import java.security.spec.PKCS8EncodedKeySpec;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;

/**

  • 极光解密
    */
    @Slf4j
    public class AuroraUserLogin {
    // 私钥
    public static final String prikey = “”;

    /**

    • 获取phone

    • @param loginToken

    • @return

    • @throws Exception
      */
      public static String decrypt(String loginToken) throws Exception {
      String host = “https://api.verification.jpush.cn/v1/web/loginTokenVerify”;
      String appKey = “”;
      String Secret = “”;
      Map<String, Object> map = new HashMap<>();
      map.put(“loginToken”, loginToken);
      map.put(“exID”, null);

      Map<String, String> headers = new HashMap<String, String>();
      headers.put(“Authorization”,“Basic ${base64_auth_string}”);
      headers.put(“Content-Type”, “application/json; charset=UTF-8”);

      String result = HttpRequest.post(host).header(“Authorization”, "Basic " + Base64.getUrlEncoder().
      encodeToString((appKey + “:” + Secret).getBytes())).
      header(“Content-Type”,“application/json; charset=UTF-8”)
      .body(JSON.toJSONString(map))
      .execute().body();

      log.info(“result:[{}]”,result);

      JSONObject jsonObject = JSON.parseObject(result);
      log.info(“获取phone:{}”,JSON.toJSON(jsonObject));
      String cryptograph_phone = (String) jsonObject.get(“phone”);

      if(StrUtil.isBlank(cryptograph_phone)){
      throw new BizException(“极光认证出错”);
      }
      PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(Base64.getDecoder().decode(prikey));
      PrivateKey privateKey = KeyFactory.getInstance(“RSA”).generatePrivate(keySpec);

      Cipher cipher = Cipher.getInstance(“RSA”);
      cipher.init(Cipher.DECRYPT_MODE, privateKey);

      byte[] b = Base64.getDecoder().decode(cryptograph_phone);

      return new String(cipher.doFinal(b));
      }

}

  • 0
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值