mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2026-03-10 00:13:40 +08:00
微信支付逻辑修改
This commit is contained in:
@@ -13,47 +13,52 @@ import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
* 支付异步通知代金券详细
|
||||
*/
|
||||
public class WxPayOrderNotifyCoupon implements Serializable {
|
||||
/**
|
||||
* @fields serialVersionUID
|
||||
*/
|
||||
private static final long serialVersionUID = -4165343733538156097L;
|
||||
|
||||
@XStreamAlias("coupon_id")
|
||||
private String couponId;
|
||||
@XStreamAlias("coupon_type")
|
||||
private String couponType;
|
||||
@XStreamAlias("coupon_fee")
|
||||
private Integer couponFee;
|
||||
|
||||
public String getCouponId() {
|
||||
return couponId;
|
||||
}
|
||||
public void setCouponId(String couponId) {
|
||||
this.couponId = couponId;
|
||||
}
|
||||
public String getCouponType() {
|
||||
return couponType;
|
||||
}
|
||||
public void setCouponType(String couponType) {
|
||||
this.couponType = couponType;
|
||||
}
|
||||
public Integer getCouponFee() {
|
||||
return couponFee;
|
||||
}
|
||||
public void setCouponFee(Integer couponFee) {
|
||||
this.couponFee = couponFee;
|
||||
}
|
||||
|
||||
public Map<String,String> toMap(int index){
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("coupon_id_"+index, this.getCouponId());
|
||||
map.put("coupon_type_"+index, this.getCouponType());
|
||||
map.put("coupon_fee_"+index, this.getCouponFee()+"");
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this,ToStringStyle.MULTI_LINE_STYLE);
|
||||
}
|
||||
/**
|
||||
* @fields serialVersionUID
|
||||
*/
|
||||
private static final long serialVersionUID = -4165343733538156097L;
|
||||
|
||||
@XStreamAlias("coupon_id")
|
||||
private String couponId;
|
||||
@XStreamAlias("coupon_type")
|
||||
private String couponType;
|
||||
@XStreamAlias("coupon_fee")
|
||||
private Integer couponFee;
|
||||
|
||||
public String getCouponId() {
|
||||
return couponId;
|
||||
}
|
||||
|
||||
public void setCouponId(String couponId) {
|
||||
this.couponId = couponId;
|
||||
}
|
||||
|
||||
public String getCouponType() {
|
||||
return couponType;
|
||||
}
|
||||
|
||||
public void setCouponType(String couponType) {
|
||||
this.couponType = couponType;
|
||||
}
|
||||
|
||||
public Integer getCouponFee() {
|
||||
return couponFee;
|
||||
}
|
||||
|
||||
public void setCouponFee(Integer couponFee) {
|
||||
this.couponFee = couponFee;
|
||||
}
|
||||
|
||||
public Map<String, String> toMap(int index) {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("coupon_id_" + index, this.getCouponId());
|
||||
map.put("coupon_type_" + index, this.getCouponType());
|
||||
map.put("coupon_fee_" + index, this.getCouponFee() + "");
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return ToStringBuilder.reflectionToString(this, ToStringStyle.MULTI_LINE_STYLE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package me.chanjar.weixin.mp.bean.pay;
|
||||
|
||||
|
||||
import com.thoughtworks.xstream.XStream;
|
||||
import com.thoughtworks.xstream.annotations.XStreamAlias;
|
||||
import com.thoughtworks.xstream.annotations.XStreamOmitField;
|
||||
@@ -9,53 +8,53 @@ import me.chanjar.weixin.common.util.xml.XStreamInitializer;
|
||||
|
||||
@XStreamAlias("xml")
|
||||
public class WxPayOrderNotifyResponse {
|
||||
@XStreamOmitField
|
||||
private transient static final String FAIL ="FAIL";
|
||||
@XStreamOmitField
|
||||
private transient static final String SUCCESS ="SUCCESS";
|
||||
|
||||
@XStreamAlias("return_code")
|
||||
private String returnCode;
|
||||
@XStreamAlias("return_msg")
|
||||
private String returnMsg;
|
||||
|
||||
|
||||
public String getReturnCode() {
|
||||
return returnCode;
|
||||
}
|
||||
public void setReturnCode(String returnCode) {
|
||||
this.returnCode = returnCode;
|
||||
}
|
||||
public String getReturnMsg() {
|
||||
return returnMsg;
|
||||
}
|
||||
public void setReturnMsg(String returnMsg) {
|
||||
this.returnMsg = returnMsg;
|
||||
}
|
||||
|
||||
@XStreamOmitField
|
||||
private transient static final String FAIL = "FAIL";
|
||||
@XStreamOmitField
|
||||
private transient static final String SUCCESS = "SUCCESS";
|
||||
|
||||
public WxPayOrderNotifyResponse() {
|
||||
super();
|
||||
}
|
||||
public WxPayOrderNotifyResponse(String returnCode, String returnMsg) {
|
||||
super();
|
||||
this.returnCode = returnCode;
|
||||
this.returnMsg = returnMsg;
|
||||
}
|
||||
|
||||
|
||||
public static String fail(String msg){
|
||||
WxPayOrderNotifyResponse response = new WxPayOrderNotifyResponse(FAIL,msg);
|
||||
XStream xstream = XStreamInitializer.getInstance();
|
||||
xstream.autodetectAnnotations(true);
|
||||
return xstream.toXML(response);
|
||||
}
|
||||
|
||||
|
||||
public static String success(String msg){
|
||||
WxPayOrderNotifyResponse response = new WxPayOrderNotifyResponse(SUCCESS,msg);
|
||||
XStream xstream = XStreamInitializer.getInstance();
|
||||
xstream.autodetectAnnotations(true);
|
||||
return xstream.toXML(response);
|
||||
}
|
||||
@XStreamAlias("return_code")
|
||||
private String returnCode;
|
||||
@XStreamAlias("return_msg")
|
||||
private String returnMsg;
|
||||
|
||||
public String getReturnCode() {
|
||||
return returnCode;
|
||||
}
|
||||
|
||||
public void setReturnCode(String returnCode) {
|
||||
this.returnCode = returnCode;
|
||||
}
|
||||
|
||||
public String getReturnMsg() {
|
||||
return returnMsg;
|
||||
}
|
||||
|
||||
public void setReturnMsg(String returnMsg) {
|
||||
this.returnMsg = returnMsg;
|
||||
}
|
||||
|
||||
public WxPayOrderNotifyResponse() {
|
||||
super();
|
||||
}
|
||||
|
||||
public WxPayOrderNotifyResponse(String returnCode, String returnMsg) {
|
||||
super();
|
||||
this.returnCode = returnCode;
|
||||
this.returnMsg = returnMsg;
|
||||
}
|
||||
|
||||
public static String fail(String msg) {
|
||||
WxPayOrderNotifyResponse response = new WxPayOrderNotifyResponse(FAIL, msg);
|
||||
XStream xstream = XStreamInitializer.getInstance();
|
||||
xstream.autodetectAnnotations(true);
|
||||
return xstream.toXML(response);
|
||||
}
|
||||
|
||||
public static String success(String msg) {
|
||||
WxPayOrderNotifyResponse response = new WxPayOrderNotifyResponse(SUCCESS, msg);
|
||||
XStream xstream = XStreamInitializer.getInstance();
|
||||
xstream.autodetectAnnotations(true);
|
||||
return xstream.toXML(response);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,107 +24,107 @@ import me.chanjar.weixin.mp.bean.pay.result.WxPayOrderNotifyResult;
|
||||
|
||||
public class WxPayOrderNotifyResultConverter extends AbstractReflectionConverter {
|
||||
|
||||
public WxPayOrderNotifyResultConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
|
||||
super(mapper, reflectionProvider);
|
||||
}
|
||||
public WxPayOrderNotifyResultConverter(Mapper mapper, ReflectionProvider reflectionProvider) {
|
||||
super(mapper, reflectionProvider);
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public boolean canConvert(Class type) {
|
||||
return type.equals(WxPayOrderNotifyResult.class);
|
||||
}
|
||||
@Override
|
||||
@SuppressWarnings("rawtypes")
|
||||
public boolean canConvert(Class type) {
|
||||
return type.equals(WxPayOrderNotifyResult.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void marshal(Object original, HierarchicalStreamWriter writer, MarshallingContext context) {
|
||||
super.marshal(original, writer, context);
|
||||
WxPayOrderNotifyResult obj = (WxPayOrderNotifyResult) original;
|
||||
List<WxPayOrderNotifyCoupon> list = obj.getCouponList();
|
||||
if (list == null || list.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
WxPayOrderNotifyCoupon coupon = list.get(i);
|
||||
writer.startNode("coupon_id_" + i);
|
||||
writer.setValue(coupon.getCouponId());
|
||||
writer.endNode();
|
||||
writer.startNode("coupon_type_" + i);
|
||||
writer.setValue(coupon.getCouponType());
|
||||
writer.endNode();
|
||||
writer.startNode("coupon_fee_" + i);
|
||||
writer.setValue(coupon.getCouponFee() + "");
|
||||
writer.endNode();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void marshal(Object original, HierarchicalStreamWriter writer, MarshallingContext context) {
|
||||
super.marshal(original, writer, context);
|
||||
WxPayOrderNotifyResult obj = (WxPayOrderNotifyResult) original;
|
||||
List<WxPayOrderNotifyCoupon> list = obj.getCouponList();
|
||||
if (list == null || list.size() == 0) {
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
WxPayOrderNotifyCoupon coupon = list.get(i);
|
||||
writer.startNode("coupon_id_" + i);
|
||||
writer.setValue(coupon.getCouponId());
|
||||
writer.endNode();
|
||||
writer.startNode("coupon_type_" + i);
|
||||
writer.setValue(coupon.getCouponType());
|
||||
writer.endNode();
|
||||
writer.startNode("coupon_fee_" + i);
|
||||
writer.setValue(coupon.getCouponFee() + "");
|
||||
writer.endNode();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void marshallField(MarshallingContext context, Object newObj, Field field) {
|
||||
if (field.getName().equals("couponList")) {
|
||||
return;
|
||||
} else {
|
||||
super.marshallField(context, newObj, field);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
protected void marshallField(MarshallingContext context, Object newObj, Field field) {
|
||||
if (field.getName().equals("couponList")) {
|
||||
return;
|
||||
} else {
|
||||
super.marshallField(context, newObj, field);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
|
||||
WxPayOrderNotifyResult obj = new WxPayOrderNotifyResult();
|
||||
@Override
|
||||
public Object unmarshal(HierarchicalStreamReader reader, UnmarshallingContext context) {
|
||||
WxPayOrderNotifyResult obj = new WxPayOrderNotifyResult();
|
||||
|
||||
List<Field> fields = new ArrayList<>(Arrays.asList(obj.getClass().getDeclaredFields()));
|
||||
fields.addAll(Arrays.asList(obj.getClass().getSuperclass().getDeclaredFields()));
|
||||
Map<String, Field> fieldMap = getFieldMap(fields);
|
||||
List<Field> fields = new ArrayList<>(Arrays.asList(obj.getClass().getDeclaredFields()));
|
||||
fields.addAll(Arrays.asList(obj.getClass().getSuperclass().getDeclaredFields()));
|
||||
Map<String, Field> fieldMap = getFieldMap(fields);
|
||||
|
||||
List<WxPayOrderNotifyCoupon> coupons = new ArrayList<>(10);
|
||||
while (reader.hasMoreChildren()) {
|
||||
reader.moveDown();
|
||||
if (fieldMap.containsKey(reader.getNodeName())) {
|
||||
Field field = fieldMap.get(reader.getNodeName());
|
||||
setFieldValue(context, obj, field);
|
||||
} else if (StringUtils.startsWith(reader.getNodeName(), "coupon_id_")) {
|
||||
String id = (String) context.convertAnother(obj, String.class);
|
||||
getIndex(coupons, reader.getNodeName()).setCouponId(id);
|
||||
} else if (StringUtils.startsWith(reader.getNodeName(), "coupon_type_")) {
|
||||
String type = (String) context.convertAnother(obj, String.class);
|
||||
getIndex(coupons, reader.getNodeName()).setCouponType(type);
|
||||
} else if (StringUtils.startsWith(reader.getNodeName(), "coupon_fee_")) {
|
||||
Integer fee = (Integer) context.convertAnother(obj, Integer.class);
|
||||
getIndex(coupons, reader.getNodeName()).setCouponFee(fee);
|
||||
}
|
||||
reader.moveUp();
|
||||
}
|
||||
List<WxPayOrderNotifyCoupon> coupons = new ArrayList<>(10);
|
||||
while (reader.hasMoreChildren()) {
|
||||
reader.moveDown();
|
||||
if (fieldMap.containsKey(reader.getNodeName())) {
|
||||
Field field = fieldMap.get(reader.getNodeName());
|
||||
setFieldValue(context, obj, field);
|
||||
} else if (StringUtils.startsWith(reader.getNodeName(), "coupon_id_")) {
|
||||
String id = (String) context.convertAnother(obj, String.class);
|
||||
getIndex(coupons, reader.getNodeName()).setCouponId(id);
|
||||
} else if (StringUtils.startsWith(reader.getNodeName(), "coupon_type_")) {
|
||||
String type = (String) context.convertAnother(obj, String.class);
|
||||
getIndex(coupons, reader.getNodeName()).setCouponType(type);
|
||||
} else if (StringUtils.startsWith(reader.getNodeName(), "coupon_fee_")) {
|
||||
Integer fee = (Integer) context.convertAnother(obj, Integer.class);
|
||||
getIndex(coupons, reader.getNodeName()).setCouponFee(fee);
|
||||
}
|
||||
reader.moveUp();
|
||||
}
|
||||
|
||||
obj.setCouponList(coupons);
|
||||
return obj;
|
||||
}
|
||||
obj.setCouponList(coupons);
|
||||
return obj;
|
||||
}
|
||||
|
||||
private void setFieldValue(UnmarshallingContext context, WxPayOrderNotifyResult obj, Field field) {
|
||||
Object val = context.convertAnother(obj, field.getType());
|
||||
try {
|
||||
if (val != null) {
|
||||
PropertyDescriptor pd = new PropertyDescriptor(field.getName(), obj.getClass());
|
||||
pd.getWriteMethod().invoke(obj, val);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
private void setFieldValue(UnmarshallingContext context, WxPayOrderNotifyResult obj, Field field) {
|
||||
Object val = context.convertAnother(obj, field.getType());
|
||||
try {
|
||||
if (val != null) {
|
||||
PropertyDescriptor pd = new PropertyDescriptor(field.getName(), obj.getClass());
|
||||
pd.getWriteMethod().invoke(obj, val);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
|
||||
private Map<String, Field> getFieldMap(List<Field> fields) {
|
||||
Map<String, Field> fieldMap = Maps.uniqueIndex(fields, new Function<Field, String>() {
|
||||
@Override
|
||||
public String apply(Field field) {
|
||||
if (field.isAnnotationPresent(XStreamAlias.class)) {
|
||||
return field.getAnnotation(XStreamAlias.class).value();
|
||||
}
|
||||
return field.getName();
|
||||
}
|
||||
});
|
||||
return fieldMap;
|
||||
}
|
||||
private Map<String, Field> getFieldMap(List<Field> fields) {
|
||||
Map<String, Field> fieldMap = Maps.uniqueIndex(fields, new Function<Field, String>() {
|
||||
@Override
|
||||
public String apply(Field field) {
|
||||
if (field.isAnnotationPresent(XStreamAlias.class)) {
|
||||
return field.getAnnotation(XStreamAlias.class).value();
|
||||
}
|
||||
return field.getName();
|
||||
}
|
||||
});
|
||||
return fieldMap;
|
||||
}
|
||||
|
||||
private WxPayOrderNotifyCoupon getIndex(List<WxPayOrderNotifyCoupon> coupons, String nodeName) {
|
||||
Integer index = Integer.valueOf(StringUtils.substring(nodeName, nodeName.lastIndexOf("_") + 1));
|
||||
if (index >= coupons.size() || coupons.get(index) == null) {
|
||||
coupons.add(index, new WxPayOrderNotifyCoupon());
|
||||
}
|
||||
return coupons.get(index);
|
||||
}
|
||||
private WxPayOrderNotifyCoupon getIndex(List<WxPayOrderNotifyCoupon> coupons, String nodeName) {
|
||||
Integer index = Integer.valueOf(StringUtils.substring(nodeName, nodeName.lastIndexOf("_") + 1));
|
||||
if (index >= coupons.size() || coupons.get(index) == null) {
|
||||
coupons.add(index, new WxPayOrderNotifyCoupon());
|
||||
}
|
||||
return coupons.get(index);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -388,7 +388,7 @@ public class WxPayOrderNotifyResult extends WxPayBaseResult implements Serializ
|
||||
@Override
|
||||
public Map<String,String> toMap(){
|
||||
Map<String,String> resultMap = BeanUtils.xmlBean2Map(this);
|
||||
if(this.getCouponCount() > 0){
|
||||
if(this.getCouponCount() != null && this.getCouponCount() > 0){
|
||||
for (int i = 0; i < this.getCouponCount(); i++) {
|
||||
WxPayOrderNotifyCoupon coupon = couponList.get(i);
|
||||
resultMap.putAll(coupon.toMap(i));
|
||||
|
||||
Reference in New Issue
Block a user