Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
chanjarster committed May 27, 2015
2 parents 6f3dfc7 + 72db0a2 commit f0432e6
Show file tree
Hide file tree
Showing 17 changed files with 325 additions and 43 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ target
sw-pom.xml
*.iml
test-config.xml
.idea
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ weixin-java-tools
<dependency>
<groupId>me.chanjar</groupId>
<artifactId>weixin-java-mp</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
</dependency>
```

Expand All @@ -27,7 +27,7 @@ weixin-java-tools
<dependency>
<groupId>me.chanjar</groupId>
<artifactId>weixin-java-cp</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
</dependency>
```

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>me.chanjar</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
<packaging>pom</packaging>
<name>WeiXin Java Tools - Parent</name>
<description>微信公众号、企业号上级POM</description>
Expand Down
2 changes: 1 addition & 1 deletion weixin-java-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>me.chanjar</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
</parent>

<artifactId>weixin-java-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ public class WxConsts {
///////////////////////
public static final String FILE_JPG = "jpeg";
public static final String FILE_MP3 = "mp3";
public static final String FILE_ARM = "arm";
public static final String FILE_AMR = "amr";
public static final String FILE_MP4 = "mp4";


Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package me.chanjar.weixin.common.util.crypto;

import org.apache.commons.codec.digest.DigestUtils;

import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
Expand All @@ -21,7 +23,7 @@ public static String gen(String... arr) throws NoSuchAlgorithmException {
for (String a : arr) {
sb.append(a);
}
return genStr(sb.toString());
return DigestUtils.sha1Hex(sb.toString());
}

/**
Expand All @@ -40,25 +42,6 @@ public static String genWithAmple(String... arr) throws NoSuchAlgorithmException
sb.append('&');
}
}
return genStr(sb.toString());
}

public static String genStr(String str) throws NoSuchAlgorithmException {
MessageDigest sha1 = MessageDigest.getInstance("SHA1");
sha1.update(str.getBytes());
byte[] output = sha1.digest();
return bytesToHex(output);
return DigestUtils.sha1Hex(sb.toString());
}

protected static String bytesToHex(byte[] b) {
char hexDigit[] = { '0', '1', '2', '3', '4', '5', '6', '7',
'8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
StringBuffer buf = new StringBuffer();
for (int j = 0; j < b.length; j++) {
buf.append(hexDigit[(b[j] >> 4) & 0x0f]);
buf.append(hexDigit[b[j] & 0x0f]);
}
return buf.toString();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package me.chanjar.weixin.common.util.crypto;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.digest.DigestUtils;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.xml.sax.InputSource;
Expand All @@ -27,8 +28,7 @@
import java.io.StringReader;
import java.nio.charset.Charset;
import java.security.NoSuchAlgorithmException;
import java.util.Arrays;
import java.util.Random;
import java.util.*;

public class WxCryptUtil {

Expand Down Expand Up @@ -224,6 +224,36 @@ public String decrypt(String cipherText) {

}

/**
* 微信公众号支付签名算法(详见:http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=4_3)
* @param packageParams 原始参数
* @param signKey 加密Key(即 商户Key)
* @param charset 编码
* @return 签名字符串
*/
public static String createSign(Map<String, String> packageParams, String signKey) {
SortedMap<String, String> sortedMap = new TreeMap<String, String>();
sortedMap.putAll(packageParams);

List<String> keys = new ArrayList<String>(packageParams.keySet());
Collections.sort(keys);


StringBuffer toSign = new StringBuffer();
for (String key : keys) {
String value = packageParams.get(key);
if (null != value && !"".equals(value) && !"sign".equals(key)
&& !"key".equals(key)) {
toSign.append(key + "=" + value + "&");
}
}
toSign.append("key=" + signKey);
System.out.println(toSign.toString());
String sign = DigestUtils.md5Hex(toSign.toString())
.toUpperCase();
return sign;
}

/**
* 将一个数字转换成生成4个字节的网络字节序bytes数组
*
Expand Down
2 changes: 1 addition & 1 deletion weixin-java-cp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>me.chanjar</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
</parent>

<artifactId>weixin-java-cp</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ WxMediaUploadResult mediaUpload(String mediaType, String fileType, InputStream i
* @param tagId
* @param userIds
*/
void tagAddUsers(String tagId, List<String> userIds) throws WxErrorException;
void tagAddUsers(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException;

/**
* <pre>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ public List<WxCpDepart> departGet() throws WxErrorException {
return WxCpGsonBuilder.INSTANCE.create()
.fromJson(
tmpJsonElement.getAsJsonObject().get("department"),
new TypeToken<List<WxCpDepart>>() { }.getType()
new TypeToken<List<WxCpDepart>>() {
}.getType()
);
}

Expand Down Expand Up @@ -389,7 +390,8 @@ public List<WxCpTag> tagGet() throws WxErrorException {
return WxCpGsonBuilder.INSTANCE.create()
.fromJson(
tmpJsonElement.getAsJsonObject().get("taglist"),
new TypeToken<List<WxCpTag>>() { }.getType()
new TypeToken<List<WxCpTag>>() {
}.getType()
);
}

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

@Override
public void tagAddUsers(String tagId, List<String> userIds) throws WxErrorException {
public void tagAddUsers(String tagId, List<String> userIds, List<String> partyIds) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/tag/addtagusers";
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("tagid", tagId);
JsonArray jsonArray = new JsonArray();
for (String userId : userIds) {
jsonArray.add(new JsonPrimitive(userId));
if (userIds != null) {
JsonArray jsonArray = new JsonArray();
for (String userId : userIds) {
jsonArray.add(new JsonPrimitive(userId));
}
jsonObject.add("userlist", jsonArray);
}
if (partyIds != null) {
JsonArray jsonArray = new JsonArray();
for (String userId : partyIds) {
jsonArray.add(new JsonPrimitive(userId));
}
jsonObject.add("partylist", jsonArray);
}
jsonObject.add("userlist", jsonArray);
post(url, jsonObject.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void testTagGet() throws Exception {
public void testTagAddUsers() throws Exception {
List<String> userIds = new ArrayList<String>();
userIds.add(((ApiTestModule.WxXmlCpInMemoryConfigStorage)configStorage).getUserId());
wxService.tagAddUsers(tagId, userIds);
wxService.tagAddUsers(tagId, userIds, null);
}

@Test(dependsOnMethods = "testTagAddUsers")
Expand Down
2 changes: 1 addition & 1 deletion weixin-java-mp/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<parent>
<groupId>me.chanjar</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>1.1.4</version>
<version>1.1.5</version>
</parent>
<artifactId>weixin-java-mp</artifactId>
<name>WeiXin Java Tools - MP</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ public interface WxMpConfigStorage {

public String getSecret();

public String getPartnerId();

public String getPartnerKey();

public String getToken();

public String getAesKey();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage {

protected volatile String appId;
protected volatile String secret;
protected volatile String partnerId;
protected volatile String partnerKey;
protected volatile String token;
protected volatile String accessToken;
protected volatile String aesKey;
Expand Down Expand Up @@ -168,6 +170,8 @@ public String toString() {
"appId='" + appId + '\'' +
", secret='" + secret + '\'' +
", token='" + token + '\'' +
", partnerId='" + partnerId + '\'' +
", partnerKey='" + partnerKey + '\'' +
", accessToken='" + accessToken + '\'' +
", aesKey='" + aesKey + '\'' +
", expiresTime=" + expiresTime +
Expand All @@ -179,4 +183,22 @@ public String toString() {
", jsapiTicketExpiresTime='" + jsapiTicketExpiresTime + '\'' +
'}';
}

@Override
public String getPartnerId() {
return partnerId;
}

public void setPartnerId(String partnerId) {
this.partnerId = partnerId;
}

@Override
public String getPartnerKey() {
return partnerKey;
}

public void setPartnerKey(String partnerKey) {
this.partnerKey = partnerKey;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,11 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
* 微信API的Service
Expand Down Expand Up @@ -332,6 +334,18 @@ public interface WxMpService {
*/
public WxMpQrCodeTicket qrCodeCreateLastTicket(int scene_id) throws WxErrorException;

/**
* <pre>
* 换取永久字符串二维码ticket
* 详情请见: http://mp.weixin.qq.com/wiki/index.php?title=生成带参数的二维码
* </pre>
*
* @param scene_str 参数。字符串类型长度现在为1到64
* @return
* @throws WxErrorException
*/
public WxMpQrCodeTicket qrCodeCreateLastTicket(String scene_str) throws WxErrorException;

/**
* <pre>
* 换取二维码图片文件,jpg格式
Expand Down Expand Up @@ -528,4 +542,32 @@ public interface WxMpService {
*/
void setMaxRetryTimes(int maxRetryTimes);

/**
* 统一下单(详见http://pay.weixin.qq.com/wiki/doc/api/index.php?chapter=9_1)
* 在发起微信支付前,需要调用统一下单接口,获取"预支付交易会话标识"
* @param openId 支付人openId
* @param outTradeNo 商户端对应订单号
* @param amt 金额(单位元)
* @param body 商品描述
* @param tradeType 交易类型 JSAPI,NATIVE,APP,WAP
* @param ip 发起支付的客户端IP
* @param notifyUrl 通知地址
* @return
*/
WxMpPrepayIdResult getPrepayId(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String notifyUrl);

/**
* 该接口调用“统一下单”接口,并拼装JSSDK发起支付请求需要的参数
* 详见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E5.8F.91.E8.B5.B7.E4.B8.80.E4.B8.AA.E5.BE.AE.E4.BF.A1.E6.94.AF.E4.BB.98.E8.AF.B7.E6.B1.82
* @param openId 支付人openId
* @param outTradeNo 商户端对应订单号
* @param amt 金额(单位元)
* @param body 商品描述
* @param tradeType 交易类型 JSAPI,NATIVE,APP,WAP
* @param ip 发起支付的客户端IP
* @param notifyUrl 通知地址
* @return
*/
Map<String, String> getJSSDKPayInfo(String openId, String outTradeNo, double amt, String body, String tradeType, String ip, String notifyUrl);

}
Loading

0 comments on commit f0432e6

Please sign in to comment.