Skip to content

Commit f0432e6

Browse files
committed
Merge branch 'develop'
2 parents 6f3dfc7 + 72db0a2 commit f0432e6

File tree

17 files changed

+325
-43
lines changed

17 files changed

+325
-43
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,4 @@ target
1919
sw-pom.xml
2020
*.iml
2121
test-config.xml
22+
.idea

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ weixin-java-tools
1717
<dependency>
1818
<groupId>me.chanjar</groupId>
1919
<artifactId>weixin-java-mp</artifactId>
20-
<version>1.1.4</version>
20+
<version>1.1.5</version>
2121
</dependency>
2222
```
2323

@@ -27,7 +27,7 @@ weixin-java-tools
2727
<dependency>
2828
<groupId>me.chanjar</groupId>
2929
<artifactId>weixin-java-cp</artifactId>
30-
<version>1.1.4</version>
30+
<version>1.1.5</version>
3131
</dependency>
3232
```
3333

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>me.chanjar</groupId>
77
<artifactId>weixin-java-parent</artifactId>
8-
<version>1.1.4</version>
8+
<version>1.1.5</version>
99
<packaging>pom</packaging>
1010
<name>WeiXin Java Tools - Parent</name>
1111
<description>微信公众号、企业号上级POM</description>

weixin-java-common/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>me.chanjar</groupId>
88
<artifactId>weixin-java-parent</artifactId>
9-
<version>1.1.4</version>
9+
<version>1.1.5</version>
1010
</parent>
1111

1212
<artifactId>weixin-java-common</artifactId>

weixin-java-common/src/main/java/me/chanjar/weixin/common/api/WxConsts.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public class WxConsts {
105105
///////////////////////
106106
public static final String FILE_JPG = "jpeg";
107107
public static final String FILE_MP3 = "mp3";
108-
public static final String FILE_ARM = "arm";
108+
public static final String FILE_AMR = "amr";
109109
public static final String FILE_MP4 = "mp4";
110110

111111

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/SHA1.java

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package me.chanjar.weixin.common.util.crypto;
22

3+
import org.apache.commons.codec.digest.DigestUtils;
4+
35
import java.security.MessageDigest;
46
import java.security.NoSuchAlgorithmException;
57
import java.util.Arrays;
@@ -21,7 +23,7 @@ public static String gen(String... arr) throws NoSuchAlgorithmException {
2123
for (String a : arr) {
2224
sb.append(a);
2325
}
24-
return genStr(sb.toString());
26+
return DigestUtils.sha1Hex(sb.toString());
2527
}
2628

2729
/**
@@ -40,25 +42,6 @@ public static String genWithAmple(String... arr) throws NoSuchAlgorithmException
4042
sb.append('&');
4143
}
4244
}
43-
return genStr(sb.toString());
44-
}
45-
46-
public static String genStr(String str) throws NoSuchAlgorithmException {
47-
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
48-
sha1.update(str.getBytes());
49-
byte[] output = sha1.digest();
50-
return bytesToHex(output);
45+
return DigestUtils.sha1Hex(sb.toString());
5146
}
52-
53-
protected static String bytesToHex(byte[] b) {
54-
char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7',
55-
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
56-
StringBuffer buf = new StringBuffer();
57-
for (int j = 0; j < b.length; j++) {
58-
buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
59-
buf.append(hexDigit[b[j] & 0x0f]);
60-
}
61-
return buf.toString();
62-
}
63-
64-
}
47+
}

weixin-java-common/src/main/java/me/chanjar/weixin/common/util/crypto/WxCryptUtil.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package me.chanjar.weixin.common.util.crypto;
1515

1616
import org.apache.commons.codec.binary.Base64;
17+
import org.apache.commons.codec.digest.DigestUtils;
1718
import org.w3c.dom.Document;
1819
import org.w3c.dom.Element;
1920
import org.xml.sax.InputSource;
@@ -27,8 +28,7 @@
2728
import java.io.StringReader;
2829
import java.nio.charset.Charset;
2930
import java.security.NoSuchAlgorithmException;
30-
import java.util.Arrays;
31-
import java.util.Random;
31+
import java.util.*;
3232

3333
public class WxCryptUtil {
3434

@@ -224,6 +224,36 @@ public String decrypt(String cipherText) {
224224

225225
}
226226

227+
/**
228+
* 微信公众号支付签名算法(详见:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=4_3)
229+
* @param packageParams 原始参数
230+
* @param signKey 加密Key(即 商户Key)
231+
* @param charset 编码
232+
* @return 签名字符串
233+
*/
234+
public static String createSign(Map<String, String> packageParams, String signKey) {
235+
SortedMap<String, String> sortedMap = new TreeMap<String, String>();
236+
sortedMap.putAll(packageParams);
237+
238+
List<String> keys = new ArrayList<String>(packageParams.keySet());
239+
Collections.sort(keys);
240+
241+
242+
StringBuffer toSign = new StringBuffer();
243+
for (String key : keys) {
244+
String value = packageParams.get(key);
245+
if (null != value && !"".equals(value) && !"sign".equals(key)
246+
&& !"key".equals(key)) {
247+
toSign.append(key + "=" + value + "&");
248+
}
249+
}
250+
toSign.append("key=" + signKey);
251+
System.out.println(toSign.toString());
252+
String sign = DigestUtils.md5Hex(toSign.toString())
253+
.toUpperCase();
254+
return sign;
255+
}
256+
227257
/**
228258
* 将一个数字转换成生成4个字节的网络字节序bytes数组
229259
*

weixin-java-cp/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<parent>
77
<groupId>me.chanjar</groupId>
88
<artifactId>weixin-java-parent</artifactId>
9-
<version>1.1.4</version>
9+
<version>1.1.5</version>
1010
</parent>
1111

1212
<artifactId>weixin-java-cp</artifactId>

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
399399
* @param tagId
400400
* @param userIds
401401
*/
402-
void tagAddUsers(String tagId, List<String> userIds) throws WxErrorException;
402+
void tagAddUsers(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException;
403403

404404
/**
405405
* <pre>

weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/WxCpServiceImpl.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,8 @@ public List<WxCpDepart> departGet() throws WxErrorException {
271271
return WxCpGsonBuilder.INSTANCE.create()
272272
.fromJson(
273273
tmpJsonElement.getAsJsonObject().get("department"),
274-
new TypeToken<List<WxCpDepart>>() { }.getType()
274+
new TypeToken<List<WxCpDepart>>() {
275+
}.getType()
275276
);
276277
}
277278

@@ -389,7 +390,8 @@ public List<WxCpTag> tagGet() throws WxErrorException {
389390
return WxCpGsonBuilder.INSTANCE.create()
390391
.fromJson(
391392
tmpJsonElement.getAsJsonObject().get("taglist"),
392-
new TypeToken<List<WxCpTag>>() { }.getType()
393+
new TypeToken<List<WxCpTag>>() {
394+
}.getType()
393395
);
394396
}
395397

@@ -406,15 +408,24 @@ public List<WxCpUser> tagGetUsers(String tagId) throws WxErrorException {
406408
}
407409

408410
@Override
409-
public void tagAddUsers(String tagId, List<String> userIds) throws WxErrorException {
411+
public void tagAddUsers(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException {
410412
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers";
411413
JsonObject jsonObject = new JsonObject();
412414
jsonObject.addProperty("tagid", tagId);
413-
JsonArray jsonArray = new JsonArray();
414-
for (String userId : userIds) {
415-
jsonArray.add(new JsonPrimitive(userId));
415+
if (userIds != null) {
416+
JsonArray jsonArray = new JsonArray();
417+
for (String userId : userIds) {
418+
jsonArray.add(new JsonPrimitive(userId));
419+
}
420+
jsonObject.add("userlist", jsonArray);
421+
}
422+
if (partyIds != null) {
423+
JsonArray jsonArray = new JsonArray();
424+
for (String userId : partyIds) {
425+
jsonArray.add(new JsonPrimitive(userId));
426+
}
427+
jsonObject.add("partylist", jsonArray);
416428
}
417-
jsonObject.add("userlist", jsonArray);
418429
post(url, jsonObject.toString());
419430
}
420431

0 commit comments

Comments
 (0)