Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ allprojects {
apply plugin: 'maven'

group = 'com.github.binarywang'
version = '2.4.0'
version = '2.5.0-SNAPSHOT'
}

subprojects {
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>com.github.binarywang</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>2.4.0</version>
<version>2.5.0-SNAPSHOT</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>com.github.binarywang</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>2.4.0</version>
<version>2.5.0-SNAPSHOT</version>
</parent>

<artifactId>weixin-java-common</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package me.chanjar.weixin.common.util;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import com.thoughtworks.xstream.annotations.XStreamAlias;

import me.chanjar.weixin.common.annotation.Required;
import me.chanjar.weixin.common.bean.result.WxError;
import me.chanjar.weixin.common.exception.WxErrorException;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;

/**
* <pre>
* bean操作的一些工具类
Expand All @@ -21,6 +25,7 @@
* </pre>
*/
public class BeanUtils {
private static Logger log = LoggerFactory.getLogger(BeanUtils.class);

/**
* 检查bean里标记为@Required的field是否为空,为空则抛异常
Expand Down Expand Up @@ -48,41 +53,42 @@ public static void checkRequiredFields(Object bean) throws WxErrorException {
}

if (!nullFields.isEmpty()) {
throw new WxErrorException(WxError.newBuilder().setErrorMsg("必填字段 " + nullFields + " 必须提供值").build());
String msg = "必填字段 " + nullFields + " 必须提供值";
log.debug(msg);
throw new WxErrorException(WxError.newBuilder().setErrorMsg(msg).build());
}
}

/**
* 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象
* @param bean 包含@XStreamAlias的xml bean对象
* @return map对象
*/
public static Map<String, String> xmlBean2Map(Object bean) {
Map<String, String> result = Maps.newHashMap();
List<Field> fields = new ArrayList<>( Arrays.asList(bean.getClass().getDeclaredFields()));
fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields()));
for (Field field : fields) {
try {
boolean isAccessible = field.isAccessible();
field.setAccessible(true);
if (field.get(bean) == null) {
field.setAccessible(isAccessible);
continue;
}
/**
* 将bean按照@XStreamAlias标识的字符串内容生成以之为key的map对象
*
* @param bean 包含@XStreamAlias的xml bean对象
* @return map对象
*/
public static Map<String, String> xmlBean2Map(Object bean) {
Map<String, String> result = Maps.newHashMap();
List<Field> fields = new ArrayList<>(Arrays.asList(bean.getClass().getDeclaredFields()));
fields.addAll(Arrays.asList(bean.getClass().getSuperclass().getDeclaredFields()));
for (Field field : fields) {
try {
boolean isAccessible = field.isAccessible();
field.setAccessible(true);
if (field.get(bean) == null) {
field.setAccessible(isAccessible);
continue;
}

if (field.isAnnotationPresent(XStreamAlias.class)) {
result.put(field.getAnnotation(XStreamAlias.class).value(),
field.get(bean).toString());
}
if (field.isAnnotationPresent(XStreamAlias.class)) {
result.put(field.getAnnotation(XStreamAlias.class).value(), field.get(bean).toString());
}

field.setAccessible(isAccessible);
} catch (SecurityException | IllegalArgumentException
| IllegalAccessException e) {
e.printStackTrace();
}
field.setAccessible(isAccessible);
} catch (SecurityException | IllegalArgumentException | IllegalAccessException e) {
e.printStackTrace();
}

}
}

return result;
}
return result;
}
}
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>com.github.binarywang</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>2.4.0</version>
<version>2.5.0-SNAPSHOT</version>
</parent>

<artifactId>weixin-java-cp</artifactId>
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>com.github.binarywang</groupId>
<artifactId>weixin-java-parent</artifactId>
<version>2.4.0</version>
<version>2.5.0-SNAPSHOT</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 @@ -4,6 +4,7 @@
import me.chanjar.weixin.common.util.http.ApacheHttpClientBuilder;

import javax.net.ssl.SSLContext;

import java.io.File;
import java.util.concurrent.locks.Lock;

Expand Down Expand Up @@ -81,6 +82,23 @@ public interface WxMpConfigStorage {
String getPartnerId();

String getPartnerKey();

/**
* 微信支付异步回掉地址,通知url必须为直接可访问的url,不能携带参数。
* @since 2.5.0
* @return
*/
String getNotifyURL();

/**
* 交易类型
* <pre>
* JSAPI--公众号支付、NATIVE--原生扫码支付、APP--app支付
* </pre>
* @since 2.5.0
* @return
*/
String getTradeType();

String getToken();

Expand Down Expand Up @@ -112,4 +130,5 @@ public interface WxMpConfigStorage {
* 是否自动刷新token
*/
boolean autoRefreshToken();

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ public class WxMpInMemoryConfigStorage implements WxMpConfigStorage {
protected volatile String secret;
protected volatile String partnerId;
protected volatile String partnerKey;
protected volatile String notifyURL;
protected volatile String tradeType;
protected volatile String token;
protected volatile String accessToken;
protected volatile String aesKey;
Expand Down Expand Up @@ -267,8 +269,25 @@ public String getPartnerKey() {
public void setPartnerKey(String partnerKey) {
this.partnerKey = partnerKey;
}


public String getNotifyURL() {
return notifyURL;
}

@Override
public void setNotifyURL(String notifyURL) {
this.notifyURL = notifyURL;
}

public String getTradeType() {
return tradeType;
}

public void setTradeType(String tradeType) {
this.tradeType = tradeType;
}

@Override
public File getTmpDirFile() {
return this.tmpDirFile;
}
Expand Down
Loading