Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

weixin.popular.util.WxaUtil类需要加个方法,针对小程序授权手机号转换成手机号信息 #230

Open
zyl-me opened this issue Jun 8, 2020 · 2 comments

Comments

@zyl-me
Copy link

zyl-me commented Jun 8, 2020

public static WxaUserPhoneInfo decryptUserPhoneInfo(String session_key, String encryptedData, String iv) { try { Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); Key sKeySpec = new SecretKeySpec(Base64.decodeBase64(session_key), "AES"); cipher.init(Cipher.DECRYPT_MODE, sKeySpec, new IvParameterSpec(Base64.decodeBase64(iv))); byte[] resultByte = cipher.doFinal(Base64.decodeBase64(encryptedData)); String data = new String(PKCS7Encoder.decode(resultByte), StandardCharsets.UTF_8); return JsonUtil.parseObject(data, WxaUserPhoneInfo.class); } catch (Exception e) { logger.error("", e); } return null; }

`package weixin.popular.bean.wxa;

public class WxaUserPhoneInfo {

private String phoneNumber;//用户绑定的手机号(国外手机号会有区号)

private String purePhoneNumber;//没有区号的手机号

private String countryCode;//区号

private Watermark watermark;

public String getPhoneNumber() {
	return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
	this.phoneNumber = phoneNumber;
}

public String getPurePhoneNumber() {
	return purePhoneNumber;
}

public void setPurePhoneNumber(String purePhoneNumber) {
	this.purePhoneNumber = purePhoneNumber;
}

public String getCountryCode() {
	return countryCode;
}

public void setCountryCode(String countryCode) {
	this.countryCode = countryCode;
}

public Watermark getWatermark() {
	return watermark;
}

public void setWatermark(Watermark watermark) {
	this.watermark = watermark;
}

}
`

@zyl-me
Copy link
Author

zyl-me commented Jun 8, 2020

public static WxaUserPhoneInfo decryptUserPhoneInfo(String session_key, String encryptedData, String iv) { try { Cipher cipher = Cipher.getInstance("AES/CBC/NoPadding"); Key sKeySpec = new SecretKeySpec(Base64.decodeBase64(session_key), "AES"); cipher.init(Cipher.DECRYPT_MODE, sKeySpec, new IvParameterSpec(Base64.decodeBase64(iv))); byte[] resultByte = cipher.doFinal(Base64.decodeBase64(encryptedData)); String data = new String(PKCS7Encoder.decode(resultByte), StandardCharsets.UTF_8); return JsonUtil.parseObject(data, WxaUserPhoneInfo.class); } catch (Exception e) { logger.error("", e); } return null; }

@zyl-me
Copy link
Author

zyl-me commented Jun 8, 2020

`package weixin.popular.bean.wxa;

public class WxaUserPhoneInfo {

private String phoneNumber;//用户绑定的手机号(国外手机号会有区号)

private String purePhoneNumber;//没有区号的手机号

private String countryCode;//区号

private Watermark watermark;

public String getPhoneNumber() {
	return phoneNumber;
}

public void setPhoneNumber(String phoneNumber) {
	this.phoneNumber = phoneNumber;
}

public String getPurePhoneNumber() {
	return purePhoneNumber;
}

public void setPurePhoneNumber(String purePhoneNumber) {
	this.purePhoneNumber = purePhoneNumber;
}

public String getCountryCode() {
	return countryCode;
}

public void setCountryCode(String countryCode) {
	this.countryCode = countryCode;
}

public Watermark getWatermark() {
	return watermark;
}

public void setWatermark(Watermark watermark) {
	this.watermark = watermark;
}

}
`

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant