Skip to content

Commit 963a2e0

Browse files
committed
fix signature encoding charset error
1 parent c85ad67 commit 963a2e0

7 files changed

Lines changed: 18 additions & 8 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.1.6
2+
* 修正:
3+
签名内容编码问题
4+
15
## 2.1.5
26
* 修改:
37
补充 RedEnvelope、Transfer 缺少字段

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ maven 远程仓库
3434
<dependency>
3535
<groupId>Pingplusplus</groupId>
3636
<artifactId>pingpp-java</artifactId>
37-
<version>2.1.5</version>
37+
<version>2.1.6</version>
3838
<type>jar</type>
3939
</dependency>
4040
```
@@ -52,7 +52,7 @@ repositories {
5252

5353
安装 Ping++ SDK
5454
```
55-
compile 'Pingplusplus:pingpp-java:2.1.5'
55+
compile 'Pingplusplus:pingpp-java:2.1.6'
5656
```
5757

5858
### 初始化

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2.1.5
1+
2.1.6

src/com/pingplusplus/Pingpp.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public abstract class Pingpp {
1111
/**
1212
* version
1313
*/
14-
public static final String VERSION = "2.1.5";
14+
public static final String VERSION = "2.1.6";
1515
/**
1616
* api key
1717
*/

src/com/pingplusplus/net/APIResource.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ private static String generateSign(String data)
588588
byte[] keyBytes = new byte[inputStream.available()];
589589
inputStream.read(keyBytes);
590590
inputStream.close();
591-
String keyString = new String(keyBytes, "UTF-8");
591+
String keyString = new String(keyBytes, CHARSET);
592592
Pingpp.privateKey = keyString.replaceAll("(-+BEGIN (RSA )?PRIVATE KEY-+\\r?\\n|-+END (RSA )?PRIVATE KEY-+\\r?\\n?)", "");
593593
}
594594

@@ -619,7 +619,7 @@ private static String generateSign(String data)
619619

620620
Signature signature = Signature.getInstance("SHA256withRSA");
621621
signature.initSign(privateKey);
622-
signature.update(data.getBytes());
622+
signature.update(data.getBytes(CHARSET));
623623
byte[] signBytes = signature.sign();
624624

625625
return Base64.encodeBase64String(signBytes).replaceAll("\n|\r", "");

src/com/pingplusplus/util/WxpubOAuth.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@
2323
* 详细内容可参考http://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html
2424
*/
2525
public class WxpubOAuth {
26+
27+
/**
28+
* URLEncoder charset
29+
*/
30+
public static final String CHARSET = "UTF-8";
31+
2632
/**
2733
* 获取微信公众号授权用户唯一标识
2834
*
@@ -91,7 +97,7 @@ private static String httpBuildQuery(Map<String, String> queryString) throws Uns
9197
if (sb.length() > 0) {
9298
sb.append('&');
9399
}
94-
sb.append(URLEncoder.encode(e.getKey(), "UTF-8")).append('=').append(URLEncoder.encode(e.getValue(), "UTF-8"));
100+
sb.append(URLEncoder.encode(e.getKey(), CHARSET)).append('=').append(URLEncoder.encode(e.getValue(), CHARSET));
95101
}
96102

97103
return sb.toString();
@@ -184,7 +190,7 @@ public static String getSignature(String charge, String jsapiTicket, String url)
184190
try {
185191
MessageDigest crypt = MessageDigest.getInstance("SHA-1");
186192
crypt.reset();
187-
crypt.update(string1.getBytes("UTF-8"));
193+
crypt.update(string1.getBytes(CHARSET));
188194
signature = byteToHex(crypt.digest());
189195
} catch (NoSuchAlgorithmException e) {
190196
e.printStackTrace();

0 commit comments

Comments
 (0)