小程序
小游戏
企业微信
微信支付
扫描小程序码分享
https://mp.weixin.qq.com/debug/wxadoc/dev/api/signature.html
微信官方提供了多种编程语言的示例代码(点击下载)。每种语言类型的接口名字均一致。调用方式可以参照示例。
下载发现没有JAVA示例代码,so what ??
5 个回答
加粗
标红
插入代码
插入链接
插入图片
上传视频
官方没有JAVA示例代码的
你好,麻烦通过点击下方“反馈信息”按钮,提供出现问题的。
@William initialize();generateIV();这两个方法不存在
二楼的William ,导入的包可以发粗来看看么。AES ,Base64
initialize();
Key sKeySpec = new SecretKeySpec(keyByte, "AES");
generateIV()
这些方法报错。
哈哈,谢谢楼上的,我试试。
/** * 解密用户敏感数据
* @param encryptedData 明文
*
* @param iv 加密算法的初始向量
@param iv 加密算法的初始向量
* @param sessionId 会话ID
* @return
*/
@RequestMapping(value = "/api/v1/wx/decodeUserInfo", method = RequestMethod.GET, produces = "application/json")
@RequestMapping
(value =
"/api/v1/wx/decodeUserInfo"
, method = RequestMethod.GET, produces =
"application/json"
)
public Map<String,Object> decodeUserInfo(
public
Map<String,Object> decodeUserInfo(
@RequestParam(required = true,value = "encryptedData") String encryptedData,
@RequestParam
(required =
true
,value =
"encryptedData"
) String encryptedData,
@RequestParam(required = true,value = "iv") String iv,
"iv"
) String iv,
@RequestParam(required = true,value = "sessionId") String sessionId){
"sessionId"
) String sessionId){
//从缓存中获取session_key
Object wxSessionObj = redisUtil.get(sessionId);
if(null == wxSessionObj){
if
(
null
== wxSessionObj){
return rtnParam(40008, null);
return
rtnParam(
40008
,
);
}
String wxSessionStr = (String)wxSessionObj;
String sessionKey = wxSessionStr.split("#")[0];
String sessionKey = wxSessionStr.split(
"#"
)[
0
];
try {
try
{
AES aes = new AES();
AES aes =
new
AES();
byte[] resultByte = aes.decrypt(Base64.decodeBase64(encryptedData), Base64.decodeBase64(sessionKey), Base64.decodeBase64(iv));
byte
[] resultByte = aes.decrypt(Base64.decodeBase64(encryptedData), Base64.decodeBase64(sessionKey), Base64.decodeBase64(iv));
if(null != resultByte && resultByte.length > 0){
!= resultByte && resultByte.length >
){
String userInfo = new String(resultByte, "UTF-8");
String userInfo =
String(resultByte,
"UTF-8"
return rtnParam(0, userInfo);
, userInfo);
catch
(InvalidAlgorithmParameterException e) {
e.printStackTrace();
(UnsupportedEncodingException e) {
return rtnParam(50021, null);
50021
public byte[] decrypt(byte[] content, byte[] keyByte, byte[] ivByte) throws InvalidAlgorithmParameterException { initialize();
[] decrypt(
[] content,
[] keyByte,
[] ivByte)
throws
InvalidAlgorithmParameterException { initialize();
Cipher cipher = Cipher.getInstance(
"AES/CBC/PKCS7Padding"
Key sKeySpec =
SecretKeySpec(keyByte,
"AES"
cipher.init(Cipher.DECRYPT_MODE, sKeySpec, generateIV(ivByte));
// 初始化
[] result = cipher.doFinal(content);
result;
(NoSuchAlgorithmException e) {
(NoSuchPaddingException e) {
(InvalidKeyException e) {
(IllegalBlockSizeException e) {
(BadPaddingException e) {
(NoSuchProviderException e) {
// TODO Auto-generated catch block
(Exception e) {
关注后,可在微信内接收相应的重要提醒。
请使用微信扫描二维码关注 “微信开放社区” 公众号
官方没有JAVA示例代码的
@William initialize();generateIV();这两个方法不存在
二楼的William ,导入的包可以发粗来看看么。AES ,Base64
initialize();
Key sKeySpec = new SecretKeySpec(keyByte, "AES");
generateIV()
这些方法报错。
哈哈,谢谢楼上的,我试试。
/** * 解密用户敏感数据
*
@param encryptedData 明文*
@param iv 加密算法的初始向量
* @param sessionId 会话ID
* @return
*/
@RequestMapping
(value =
"/api/v1/wx/decodeUserInfo"
, method = RequestMethod.GET, produces =
"application/json"
)
public
Map<String,Object> decodeUserInfo(
@RequestParam
(required =
true
,value =
"encryptedData"
) String encryptedData,
@RequestParam
(required =
true
,value =
"iv"
) String iv,
@RequestParam
(required =
true
,value =
"sessionId"
) String sessionId){
//从缓存中获取session_key
Object wxSessionObj = redisUtil.get(sessionId);
if
(
null
== wxSessionObj){
return
rtnParam(
40008
,
null
);
}
String wxSessionStr = (String)wxSessionObj;
String sessionKey = wxSessionStr.split(
"#"
)[
0
];
try
{
AES aes =
new
AES();
byte
[] resultByte = aes.decrypt(Base64.decodeBase64(encryptedData), Base64.decodeBase64(sessionKey), Base64.decodeBase64(iv));
if
(
null
!= resultByte && resultByte.length >
0
){
String userInfo =
new
String(resultByte,
"UTF-8"
);
return
rtnParam(
0
, userInfo);
}
}
catch
(InvalidAlgorithmParameterException e) {
e.printStackTrace();
}
catch
(UnsupportedEncodingException e) {
e.printStackTrace();
}
return
rtnParam(
50021
,
null
);
}
public
byte
[] decrypt(
byte
[] content,
byte
[] keyByte,
byte
[] ivByte)
throws
InvalidAlgorithmParameterException { initialize();
try
{
Cipher cipher = Cipher.getInstance(
"AES/CBC/PKCS7Padding"
);
Key sKeySpec =
new
SecretKeySpec(keyByte,
"AES"
);
cipher.init(Cipher.DECRYPT_MODE, sKeySpec, generateIV(ivByte));
// 初始化
byte
[] result = cipher.doFinal(content);
return
result;
}
catch
(NoSuchAlgorithmException e) {
e.printStackTrace();
}
catch
(NoSuchPaddingException e) {
e.printStackTrace();
}
catch
(InvalidKeyException e) {
e.printStackTrace();
}
catch
(IllegalBlockSizeException e) {
e.printStackTrace();
}
catch
(BadPaddingException e) {
e.printStackTrace();
}
catch
(NoSuchProviderException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
catch
(Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}