提交dubbo版本
This commit is contained in:
parent
ddae755c5f
commit
eb53349307
1
pom.xml
1
pom.xml
|
|
@ -16,6 +16,7 @@
|
|||
<module>xxpay-mgr</module>
|
||||
<module>xxpay-shop</module>
|
||||
<module>xxpay4spring-cloud</module>
|
||||
<module>xxpay4dubbo</module>
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
|
|
|
|||
|
|
@ -11,10 +11,14 @@
|
|||
<description>xxpay-common</description>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<fastjson.version>1.2.7</fastjson.version>
|
||||
<logback-classic.version>1.1.7</logback-classic.version>
|
||||
<slf4j-api.version>1.7.7</slf4j-api.version>
|
||||
<commons-lang3.version>3.4</commons-lang3.version>
|
||||
<commons-lang3.version>3.5</commons-lang3.version>
|
||||
<commons.beanutils.version>1.7.0</commons.beanutils.version>
|
||||
<commons.collections.version>3.2.2</commons.collections.version>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
|
|
@ -43,6 +47,16 @@
|
|||
<artifactId>commons-lang3</artifactId>
|
||||
<version>${commons-lang3.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-beanutils</groupId>
|
||||
<artifactId>commons-beanutils</artifactId>
|
||||
<version>${commons.beanutils.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-collections</groupId>
|
||||
<artifactId>commons-collections</artifactId>
|
||||
<version>${commons.collections.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,34 @@
|
|||
package org.xxpay.common.constant;
|
||||
|
||||
/**
|
||||
* Created by admin on 2016/4/27.
|
||||
*/
|
||||
public class Constant {
|
||||
|
||||
// 账户业务模块流水号前缀(account)
|
||||
public static final String AC_BIZ_SEQUENCE_NO_PREFIX = "ac";
|
||||
// 账户业务模块流水号前缀(config)
|
||||
public static final String CF_BIZ_SEQUENCE_NO_PREFIX = "cf";
|
||||
// 账户业务模块流水号前缀(metadata)
|
||||
public static final String MD_BIZ_SEQUENCE_NO_PREFIX = "md";
|
||||
public static final String ME_BIZ_SEQUENCE_NO_PREFIX = "me";
|
||||
// 认证业务模块流水号前缀(auth)
|
||||
public static final String AU_BIZ_SEQUENCE_NO_PREFIX = "au";
|
||||
// 交易业务模块流水号前缀(trans)
|
||||
public static final String TRANS_BIZ_SEQUENCE_NO_PREFIX = "tn";
|
||||
// 日志业务模块流水号前缀(log)
|
||||
public static final String LG_BIZ_SEQUENCE_NO_PREFIX = "lg";
|
||||
// zookeeper监控业务模块流水号前缀(zk)
|
||||
public static final String ZK_BIZ_SEQUENCE_NO_PREFIX = "zk";
|
||||
// 朋友圈流水号前缀(moments)
|
||||
public static final String MM_BIZ_SEQUENCE_NO_PREFIX = "mm";
|
||||
// 背包流水号前缀(pack)
|
||||
public static final String PK_BIZ_SEQUENCE_NO_PREFIX = "pk";
|
||||
|
||||
// 随机通讯码不重复的时间间隔(ms)
|
||||
public static final long RPC_SEQ_NO_NOT_REPEAT_INTERVAL = 5 * 1000;
|
||||
|
||||
// 服务端返回map中业务数据结果对应的key名称
|
||||
public static final String BIZ_RESULT_KEY = "bizResult";
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,257 @@
|
|||
package org.xxpay.common.domain;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.xxpay.common.enumm.RpcSignTypeEnum;
|
||||
import org.xxpay.common.util.*;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by admin on 2016/7/11.
|
||||
*/
|
||||
public class BaseParam extends RpcBaseParam {
|
||||
|
||||
private Map<String, Object> bizParamMap;
|
||||
|
||||
public BaseParam() {}
|
||||
|
||||
/**
|
||||
* 不需要业务签名的构造器
|
||||
* @param rpcSrcSysId
|
||||
* @param rpcSignKey
|
||||
* @param bizSeqNoPrefix
|
||||
*/
|
||||
public BaseParam(String rpcSrcSysId, String rpcSignKey, String bizSeqNoPrefix) {
|
||||
super.rpcSrcSysId = rpcSrcSysId;
|
||||
super.rpcDateTime = DateUtils.getCurrentTimeStrDefault();
|
||||
super.rpcSeqNo = RandomStrUtils.getInstance().getRandomString();
|
||||
super.rpcSignType = RpcSignTypeEnum.SHA1_SIGN.getCode();
|
||||
super.bizSeqNo = BizSequenceUtils.getInstance().generateBizSeqNo(bizSeqNoPrefix);
|
||||
StringBuffer decriptBuffer = new StringBuffer();
|
||||
decriptBuffer.append(rpcSignKey)
|
||||
.append(super.rpcSrcSysId)
|
||||
.append(super.rpcDateTime)
|
||||
.append(super.rpcSignType)
|
||||
.append(super.bizSeqNo);
|
||||
super.rpcSign = RpcSignUtils.sha1(decriptBuffer.toString());
|
||||
this.bizParamMap = new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
/**
|
||||
* 需要业务签名的构造器
|
||||
* @param rpcSrcSysId
|
||||
* @param rpcSignKey
|
||||
* @param bizSeqNoPrefix
|
||||
* @param bizSign
|
||||
*/
|
||||
public BaseParam(String rpcSrcSysId, String rpcSignKey, String bizSeqNoPrefix, String bizSign) {
|
||||
super.rpcSrcSysId = rpcSrcSysId;
|
||||
super.rpcDateTime = DateUtils.getCurrentTimeStrDefault();
|
||||
super.rpcSeqNo = RandomStrUtils.getInstance().getRandomString();
|
||||
super.rpcSignType = RpcSignTypeEnum.SHA1_SIGN.getCode();
|
||||
super.bizSeqNo = BizSequenceUtils.getInstance().generateBizSeqNo(bizSeqNoPrefix);
|
||||
super.bizSign = bizSign;
|
||||
StringBuffer decriptBuffer = new StringBuffer();
|
||||
decriptBuffer.append(rpcSignKey)
|
||||
.append(super.rpcSrcSysId)
|
||||
.append(super.rpcDateTime)
|
||||
.append(super.rpcSignType)
|
||||
.append(super.bizSeqNo)
|
||||
.append(super.bizSign);
|
||||
super.rpcSign = RpcSignUtils.sha1(decriptBuffer.toString());
|
||||
this.bizParamMap = new HashMap<String, Object>();
|
||||
}
|
||||
|
||||
public Map<String, Object> getBizParamMap() {
|
||||
return bizParamMap;
|
||||
}
|
||||
|
||||
public void setBizParamMap(Map<String, Object> bizParamMap) {
|
||||
this.bizParamMap = bizParamMap;
|
||||
}
|
||||
|
||||
public String toJson() {
|
||||
return JsonUtil.object2Json(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuffer sb = new StringBuffer("BaseParam{");
|
||||
sb.append("rpcSrcSysId='").append(rpcSrcSysId).append('\'');
|
||||
sb.append(", rpcDateTime='").append(rpcDateTime).append('\'');
|
||||
sb.append(", rpcSeqNo='").append(rpcSeqNo).append('\'');
|
||||
sb.append(", rpcSignType=").append(rpcSignType);
|
||||
sb.append(", rpcSign='").append(rpcSign).append('\'');
|
||||
sb.append(", bizSeqNo='").append(bizSeqNo).append('\'');
|
||||
sb.append(", bizSign='").append(bizSign).append('\'');
|
||||
sb.append(", bizParamMap=").append(bizParamMap);
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public boolean isNullValue(String key) {
|
||||
Object objValue = this.bizParamMap.get(key);
|
||||
return objValue == null || StringUtils.isBlank(objValue.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断bizParamMap中的参数是否全部为空,是则返回true,否则返回false
|
||||
* @param excludeKeys
|
||||
* @return
|
||||
*/
|
||||
public boolean isInvalidMapValue(Object... excludeKeys) {
|
||||
if (this.bizParamMap == null || this.bizParamMap.isEmpty()) {
|
||||
return true;
|
||||
}
|
||||
List<Object> list = Arrays.asList(excludeKeys);
|
||||
for (Map.Entry<String, Object> entry : this.bizParamMap.entrySet()) {
|
||||
if (list.contains(entry.getKey())) {
|
||||
continue;
|
||||
}
|
||||
Object value = entry.getValue();
|
||||
if (value != null ) {
|
||||
if (value instanceof String) {
|
||||
if (StringUtils.isNotBlank(value.toString())) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取long类型参数
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public Long getLongBizParam(String name) {
|
||||
if (isNullValue(name)) {
|
||||
return null;
|
||||
}
|
||||
return Long.valueOf(bizParamMap.get(name).toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取int类型参数
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public Integer getIntBizParam(String name) {
|
||||
if (isNullValue(name)) {
|
||||
return null;
|
||||
}
|
||||
return Integer.valueOf(bizParamMap.get(name).toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取int类型参数,如果为空返回defaultValue
|
||||
* @param name
|
||||
* @param defaultValue
|
||||
* @return
|
||||
*/
|
||||
public Integer getIntBizParam(String name, int defaultValue) {
|
||||
if (isNullValue(name)) {
|
||||
return defaultValue;
|
||||
}
|
||||
return Integer.valueOf(bizParamMap.get(name).toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取short类型参数
|
||||
* @param name
|
||||
* @return
|
||||
*/
|
||||
public Short getShortBizParam(String name) {
|
||||
if (isNullValue(name)) {
|
||||
return null;
|
||||
}
|
||||
return Short.valueOf(bizParamMap.get(name).toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取string类型参数,如果为空返回defaultValue
|
||||
* @param name
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public String getStringBizParam(String name, String defaultValue){
|
||||
if (isNullValue(name)) {
|
||||
return defaultValue;
|
||||
}
|
||||
return bizParamMap.get(name).toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取string类型参数
|
||||
* @param name
|
||||
* @param
|
||||
* @return
|
||||
*/
|
||||
public String getStringBizParam(String name){
|
||||
if (isNullValue(name)) {
|
||||
return null;
|
||||
}
|
||||
return bizParamMap.get(name).toString();
|
||||
}
|
||||
|
||||
public List<Short> getShortListBizParam(String name) {
|
||||
if (isNullValue(name)) {
|
||||
return null;
|
||||
}
|
||||
List<Number> numberList = (List<Number>) bizParamMap.get(name);
|
||||
if (numberList == null) {
|
||||
return null;
|
||||
}
|
||||
List<Short> shortList = new ArrayList<Short>(numberList.size());
|
||||
for (Number number : numberList) {
|
||||
Short value = number.shortValue();
|
||||
shortList.add(value);
|
||||
}
|
||||
return shortList;
|
||||
}
|
||||
|
||||
public List<Integer> getIntegerListBizParam(String name) {
|
||||
if (isNullValue(name)) {
|
||||
return null;
|
||||
}
|
||||
List<Number> numberList = (List<Number>) bizParamMap.get(name);
|
||||
if (numberList == null) {
|
||||
return null;
|
||||
}
|
||||
List<Integer> integerList = new ArrayList<Integer>(numberList.size());
|
||||
for (Number number : numberList) {
|
||||
Integer value = number.intValue();
|
||||
integerList.add(value);
|
||||
}
|
||||
return integerList;
|
||||
}
|
||||
|
||||
public List<Long> getLongListBizParam(String name) {
|
||||
if (isNullValue(name)) {
|
||||
return null;
|
||||
}
|
||||
List<Number> numberList = (List<Number>) bizParamMap.get(name);
|
||||
if (numberList == null) {
|
||||
return null;
|
||||
}
|
||||
List<Long> longList = new ArrayList<Long>(numberList.size());
|
||||
for (Number number : numberList) {
|
||||
Long value = number.longValue();
|
||||
longList.add(value);
|
||||
}
|
||||
return longList;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
BaseParam baseParam = new BaseParam();
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
map.put("a", null);
|
||||
map.put("b", "");
|
||||
baseParam.setBizParamMap(map);
|
||||
System.out.println(baseParam.isInvalidMapValue(""));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,195 @@
|
|||
package org.xxpay.common.domain;
|
||||
|
||||
import org.xxpay.common.enumm.RpcSignTypeEnum;
|
||||
import org.xxpay.common.util.*;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 服务接口调用入参基类
|
||||
* Created by admin on 2016/4/27.
|
||||
*/
|
||||
public class RpcBaseParam implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
/**
|
||||
* 调用方ID(由RPC服务端分配)
|
||||
*/
|
||||
protected String rpcSrcSysId;
|
||||
/**
|
||||
* 业务调用当前时间(格式:yyyyMMddHHmmssSSS)
|
||||
*/
|
||||
protected String rpcDateTime;
|
||||
/**
|
||||
* 随机通讯码(要求一定时间段内不重复)
|
||||
*/
|
||||
protected String rpcSeqNo;
|
||||
/**
|
||||
* 签名计算方法
|
||||
* 参见RpcSignTypeEnum
|
||||
* 0: 明文
|
||||
* 1: SHA-1
|
||||
*/
|
||||
protected Integer rpcSignType;
|
||||
/**
|
||||
* 签名(用于验证调用方的合法性)
|
||||
* 签名计算方法: 签名方法(key(由RPC服务端分配,不在通讯中传递)+scrSysId+rpcDateTime(yyyyMMddHHmmssSSS)+rpcSignType+bizSeqNo+bizSign),如果字段为null则不参与
|
||||
* eg. sha1(key+srcSysId+curDateTime+rpcSignType+bizSeqNo+bizSign)
|
||||
*/
|
||||
protected String rpcSign;
|
||||
/**
|
||||
* 业务流水号(唯一标示一笔业务)
|
||||
* 由业务前缀(2字符,参见Constant.MP_BIZ_SEQUENCE_NO_PREFIX)+日期时间(yyyyMMddHHmmss)+流水号(6位数字)组成
|
||||
* eg. Constant.MP_BIZ_SEQUENCE_NO_PREFIX)+DateUtils.getCurrentTimeStr("yyyyMMddHHmmss")
|
||||
* +BizSequenceUtils.getInstance().generateBizSeqNo()
|
||||
*/
|
||||
protected String bizSeqNo;
|
||||
/**
|
||||
* 业务签名(计算由各业务系统定义)
|
||||
*/
|
||||
protected String bizSign;
|
||||
|
||||
public RpcBaseParam() {}
|
||||
|
||||
/**
|
||||
* 不需要业务签名的构造器
|
||||
* @param rpcSrcSysId
|
||||
* @param rpcSignKey
|
||||
* @param bizSeqNoPrefix
|
||||
*/
|
||||
public RpcBaseParam(String rpcSrcSysId, String rpcSignKey, String bizSeqNoPrefix) {
|
||||
this.rpcSrcSysId = rpcSrcSysId;
|
||||
this.rpcDateTime = DateUtils.getCurrentTimeStrDefault();
|
||||
this.rpcSeqNo = RandomStrUtils.getInstance().getRandomString();
|
||||
this.rpcSignType = RpcSignTypeEnum.SHA1_SIGN.getCode();
|
||||
this.bizSeqNo = BizSequenceUtils.getInstance().generateBizSeqNo(bizSeqNoPrefix);
|
||||
StringBuffer decriptBuffer = new StringBuffer();
|
||||
decriptBuffer.append(rpcSignKey)
|
||||
.append(this.rpcSrcSysId)
|
||||
.append(this.rpcDateTime)
|
||||
.append(this.rpcSignType)
|
||||
.append(this.bizSeqNo);
|
||||
this.rpcSign = RpcSignUtils.sha1(decriptBuffer.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
* 需要业务签名的构造器
|
||||
* @param rpcSrcSysId
|
||||
* @param rpcSignKey
|
||||
* @param bizSeqNoPrefix
|
||||
* @param bizSign
|
||||
*/
|
||||
public RpcBaseParam(String rpcSrcSysId, String rpcSignKey, String bizSeqNoPrefix, String bizSign) {
|
||||
this.rpcSrcSysId = rpcSrcSysId;
|
||||
this.rpcDateTime = DateUtils.getCurrentTimeStrDefault();
|
||||
this.rpcSeqNo = RandomStrUtils.getInstance().getRandomString();
|
||||
this.rpcSignType = RpcSignTypeEnum.SHA1_SIGN.getCode();
|
||||
this.bizSeqNo = BizSequenceUtils.getInstance().generateBizSeqNo(bizSeqNoPrefix);
|
||||
this.bizSign = bizSign;
|
||||
StringBuffer decriptBuffer = new StringBuffer();
|
||||
decriptBuffer.append(rpcSignKey)
|
||||
.append(this.rpcSrcSysId)
|
||||
.append(this.rpcDateTime)
|
||||
.append(this.rpcSignType)
|
||||
.append(this.bizSeqNo)
|
||||
.append(this.bizSign);
|
||||
this.rpcSign = RpcSignUtils.sha1(decriptBuffer.toString());
|
||||
}
|
||||
|
||||
public String getRpcSrcSysId() {
|
||||
return rpcSrcSysId;
|
||||
}
|
||||
|
||||
public void setRpcSrcSysId(String rpcSrcSysId) {
|
||||
this.rpcSrcSysId = rpcSrcSysId;
|
||||
}
|
||||
|
||||
public String getRpcDateTime() {
|
||||
return rpcDateTime;
|
||||
}
|
||||
|
||||
public void setRpcDateTime(String rpcDateTime) {
|
||||
this.rpcDateTime = rpcDateTime;
|
||||
}
|
||||
|
||||
public String getRpcSeqNo() {
|
||||
return rpcSeqNo;
|
||||
}
|
||||
|
||||
public void setRpcSeqNo(String rpcSeqNo) {
|
||||
this.rpcSeqNo = rpcSeqNo;
|
||||
}
|
||||
|
||||
public Integer getRpcSignType() {
|
||||
return rpcSignType;
|
||||
}
|
||||
|
||||
public void setRpcSignType(Integer rpcSignType) {
|
||||
this.rpcSignType = rpcSignType;
|
||||
}
|
||||
|
||||
public String getBizSeqNo() {
|
||||
return bizSeqNo;
|
||||
}
|
||||
|
||||
public void setBizSeqNo(String bizSeqNo) {
|
||||
this.bizSeqNo = bizSeqNo;
|
||||
}
|
||||
|
||||
public String getBizSign() {
|
||||
return bizSign;
|
||||
}
|
||||
|
||||
public void setBizSign(String bizSign) {
|
||||
this.bizSign = bizSign;
|
||||
}
|
||||
|
||||
public String getRpcSign() {
|
||||
return rpcSign;
|
||||
}
|
||||
|
||||
public void setRpcSign(String rpcSign) {
|
||||
this.rpcSign = rpcSign;
|
||||
}
|
||||
|
||||
/*public Map<String, Object> convert2Map() {
|
||||
if (this == null) {
|
||||
return null;
|
||||
}
|
||||
return BeanConvertUtils.bean2Map(this);
|
||||
}*/
|
||||
|
||||
public static RpcBaseParam convert2Bean(Map<String, Object> map) {
|
||||
return BeanConvertUtils.map2Bean(map, RpcBaseParam.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuffer sb = new StringBuffer("RpcBaseParam{");
|
||||
sb.append("rpcSrcSysId='").append(rpcSrcSysId).append('\'');
|
||||
sb.append(", rpcDateTime='").append(rpcDateTime).append('\'');
|
||||
sb.append(", rpcSeqNo='").append(rpcSeqNo).append('\'');
|
||||
sb.append(", rpcSignType=").append(rpcSignType);
|
||||
sb.append(", rpcSign='").append(rpcSign).append('\'');
|
||||
sb.append(", bizSeqNo='").append(bizSeqNo).append('\'');
|
||||
sb.append(", bizSign='").append(bizSign).append('\'');
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Map<String, Object> convert2Map() {
|
||||
Map<String, Object> rpcMap = new HashMap<String, Object>();
|
||||
rpcMap.put("rpcSrcSysId", rpcSrcSysId);
|
||||
rpcMap.put("rpcDateTime", rpcDateTime);
|
||||
rpcMap.put("rpcSeqNo", rpcSeqNo);
|
||||
rpcMap.put("rpcSignType", rpcSignType);
|
||||
rpcMap.put("rpcSign", rpcSign);
|
||||
rpcMap.put("bizSeqNo", bizSeqNo);
|
||||
rpcMap.put("bizSign", bizSign);
|
||||
return rpcMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,83 @@
|
|||
package org.xxpay.common.domain;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 服务接口调用返回值基类
|
||||
* Created by admin on 2016/4/27.
|
||||
*/
|
||||
public class RpcBaseResult extends RpcBaseParam {
|
||||
|
||||
/**
|
||||
* RPC调用返回码
|
||||
* 0000: 成功
|
||||
* 其他: 失败(00开始标示通讯层相关错误码)
|
||||
*/
|
||||
protected String rpcRetCode;
|
||||
/**
|
||||
* RPC调用返回错误描述
|
||||
*/
|
||||
protected String rpcRetMsg;
|
||||
|
||||
/**
|
||||
* DB返回的错误码
|
||||
*/
|
||||
protected String dbErrorCode;
|
||||
|
||||
/**
|
||||
* DB返回的错误信息
|
||||
*/
|
||||
protected String dbErrorMsg;
|
||||
|
||||
public String getRpcRetCode() {
|
||||
return rpcRetCode;
|
||||
}
|
||||
|
||||
public void setRpcRetCode(String rpcRetCode) {
|
||||
this.rpcRetCode = rpcRetCode;
|
||||
}
|
||||
|
||||
public String getRpcRetMsg() {
|
||||
return rpcRetMsg;
|
||||
}
|
||||
|
||||
public void setRpcRetMsg(String rpcRetMsg) {
|
||||
this.rpcRetMsg = rpcRetMsg;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
final StringBuffer sb = new StringBuffer("RpcBaseResult{");
|
||||
sb.append("rpcSrcSysId='").append(rpcSrcSysId).append('\'');
|
||||
sb.append(", rpcDateTime='").append(rpcDateTime).append('\'');
|
||||
sb.append(", rpcSeqNo='").append(rpcSeqNo).append('\'');
|
||||
sb.append(", rpcSignType=").append(rpcSignType);
|
||||
sb.append(", rpcSign='").append(rpcSign).append('\'');
|
||||
sb.append(", bizSeqNo='").append(bizSeqNo).append('\'');
|
||||
sb.append(", bizSign='").append(bizSign).append('\'');
|
||||
sb.append(", rpcRetCode='").append(rpcRetCode).append('\'');
|
||||
sb.append(", rpcRetMsg='").append(rpcRetMsg).append('\'');
|
||||
sb.append(", dbErrorCode='").append(dbErrorCode).append('\'');
|
||||
sb.append(", dbErrorMsg='").append(dbErrorMsg).append('\'');
|
||||
sb.append('}');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public Map<String, Object> convert2Map() {
|
||||
Map<String, Object> rpcMap = new HashMap<String, Object>();
|
||||
rpcMap.put("rpcSrcSysId", rpcSrcSysId);
|
||||
rpcMap.put("rpcDateTime", rpcDateTime);
|
||||
rpcMap.put("rpcSeqNo", rpcSeqNo);
|
||||
rpcMap.put("rpcSignType", rpcSignType);
|
||||
rpcMap.put("rpcSign", rpcSign);
|
||||
rpcMap.put("bizSeqNo", bizSeqNo);
|
||||
rpcMap.put("bizSign", bizSign);
|
||||
rpcMap.put("rpcRetCode", rpcRetCode);
|
||||
rpcMap.put("rpcRetMsg", rpcRetMsg);
|
||||
rpcMap.put("dbErrorCode", dbErrorCode);
|
||||
rpcMap.put("dbErrorMsg", dbErrorMsg);
|
||||
return rpcMap;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
package org.xxpay.common.enumm;
|
||||
|
||||
/**
|
||||
* RPC调用返回码枚举类
|
||||
* 对应方法调用返回值中的rpcRetCode和rpcRetMsg
|
||||
* Created by admin on 2016/4/27.
|
||||
*/
|
||||
public enum RetEnum {
|
||||
|
||||
// 0000: 成功
|
||||
RET_SUCCESS("0000", ""),
|
||||
|
||||
// 失败(00开始标示通讯层相关错误码)
|
||||
RET_REMOTE_UNUSABLE("0001", "远程服务不可用"),
|
||||
RET_REMOTE_INVALID("0002", "客户端非法调用"),
|
||||
RET_NO_BIZ_SEQUENCE_NO("0003", "远程服务调用业务流水号不存在"),
|
||||
RET_REMOTE_CHECK_SIGN_FAIL("0004", "远程服务调用签名验证失败"),
|
||||
RET_REMOTE_RPC_SEQ_NO_REPEATED("0005", "随机通讯码在指定时间内重复"),
|
||||
RET_REMOTE_SIGN_INVALID("0006", "远程服务调用签名计算方式错误"),
|
||||
RET_REMOTE_DEAL_EXCEPTION("0007", "远程服务调用处理异常"),
|
||||
RET_REMOTE_PROTOCOL_INVALID("0008", "客户端调用协议非法"),
|
||||
RET_REMOTE_HTTP_METHOD_INVALID("0009", "客户端请求方式非法"),
|
||||
|
||||
// 失败(01开始标示参数校验相关错误码)
|
||||
RET_PARAM_NOT_FOUND("0101", "参数不存在"),
|
||||
RET_PARAM_INVALID("0102", "无效的参数"),
|
||||
RET_PARAM_TOO_LARGE_LIST("0103", "列表超长"),
|
||||
RET_PARAM_TYPE_INVALID("0104", "参数类型错误"),
|
||||
RET_CURRENT_PAGE_INVALID("0105", "当前页码非法"),
|
||||
RET_VIEW_NUMBER_INVALID("0106", "分页显示数目非法"),
|
||||
RET_VIEW_LIMIT_INVALID("0107", "数据排列显示数目非法"),
|
||||
|
||||
// 失败(02开始标示DB操作相关错误码)
|
||||
RET_DB_FAIL("0201", "数据库操作失败"),
|
||||
|
||||
// 业务相关
|
||||
RET_BIZ_DATA_NOT_EXISTS("1001", "数据不存在"),
|
||||
RET_BIZ_SING_DATA_FAIL("1002", "商户签名数据不正确"),
|
||||
RET_BIZ_WX_PAY_CREATE_FAIL("1003", "微信支付下单失败"),
|
||||
RET_BIZ_ALI_PAY_CREATE_FAIL("1004", "支付宝支付下单失败"),
|
||||
RET_BIZ_PAY_NOTIFY_VERIFY_FAIL("1005", "支付通知数据验证不正确"),
|
||||
|
||||
|
||||
// 未知错误
|
||||
RET_UNKNOWN_ERROR("9999", "未知错误");
|
||||
|
||||
private String code;
|
||||
private String message;
|
||||
|
||||
private RetEnum(String code, String message) { this.code = code;
|
||||
this.message = message; }
|
||||
|
||||
public String getCode()
|
||||
{
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public String getMessage() {
|
||||
return this.message;
|
||||
}
|
||||
|
||||
public static RetEnum getRetEnum(String code) {
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
RetEnum[] values = RetEnum.values();
|
||||
for (RetEnum e : values) {
|
||||
if (e.getCode().equals(code)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,37 @@
|
|||
package org.xxpay.common.enumm;
|
||||
|
||||
/**
|
||||
* RPC通讯层签名计算方法枚举类
|
||||
* Created by admin on 2016/5/4.
|
||||
*/
|
||||
public enum RpcSignTypeEnum {
|
||||
|
||||
NOT_SIGN(0),// 明文
|
||||
SHA1_SIGN(1);// SHA-1签名
|
||||
|
||||
private Integer code;
|
||||
|
||||
private RpcSignTypeEnum(Integer code) {
|
||||
this.code = code;
|
||||
}
|
||||
|
||||
public Integer getCode()
|
||||
{
|
||||
return this.code;
|
||||
}
|
||||
|
||||
public static RpcSignTypeEnum getRpcSignTypeEnum(Integer code) {
|
||||
if (code == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
RpcSignTypeEnum[] values =RpcSignTypeEnum.values();
|
||||
for (RpcSignTypeEnum e : values) {
|
||||
if (e.getCode().equals(code)) {
|
||||
return e;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,94 @@
|
|||
package org.xxpay.common.util;
|
||||
|
||||
import org.apache.commons.beanutils.BeanUtils;
|
||||
import org.apache.commons.beanutils.ConvertUtils;
|
||||
import org.apache.commons.beanutils.converters.*;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Date;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by admin on 2016/5/4.
|
||||
*/
|
||||
public class BeanConvertUtils {
|
||||
|
||||
static {
|
||||
// 在封装之前 注册转换器
|
||||
ConvertUtils.register(new DateTimeConverter(), Date.class);
|
||||
ConvertUtils.register(new DateTimeConverter(), java.sql.Date.class);
|
||||
ConvertUtils.register(new LongConverter(null), Long.class);
|
||||
ConvertUtils.register(new ShortConverter(null), Short.class);
|
||||
ConvertUtils.register(new IntegerConverter(null), Integer.class);
|
||||
ConvertUtils.register(new DoubleConverter(null), Double.class);
|
||||
ConvertUtils.register(new BigDecimalConverter(null), BigDecimal.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* 将javabean转换为Map
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, Object> bean2Map(Object obj) {
|
||||
try {
|
||||
Map<String, Object> map = BeanUtils.describe(obj);
|
||||
map.remove("class");
|
||||
return map;
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (NoSuchMethodException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 将Map转换为javabean
|
||||
* @param map
|
||||
* @param clazz
|
||||
* @param <T>
|
||||
* @return
|
||||
*/
|
||||
public static <T> T map2Bean(Map<String, Object> map, Class<T> clazz) {
|
||||
if (map == null || clazz == null) {
|
||||
return null;
|
||||
}
|
||||
T bean = null;
|
||||
try {
|
||||
bean = clazz.newInstance();
|
||||
BeanUtils.populate(bean, map);
|
||||
} catch (InstantiationException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return bean;
|
||||
}
|
||||
|
||||
/**
|
||||
* 对象间的属性值拷贝
|
||||
*
|
||||
* @param dest 目标对象
|
||||
* @param src 源对象
|
||||
*/
|
||||
public static void copyProperties(Object dest, Object src) {
|
||||
if (src == null || dest == null) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
BeanUtils.copyProperties(dest, src);
|
||||
} catch (IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
} catch (InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IllegalArgumentException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
package org.xxpay.common.util;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.FieldPosition;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
/**
|
||||
* 业务流水号工具类
|
||||
* Created by admin on 2016/4/28.
|
||||
*/
|
||||
public class BizSequenceUtils {
|
||||
|
||||
private static Object lock = new Object();
|
||||
|
||||
private static BizSequenceUtils instance;
|
||||
|
||||
/**
|
||||
* The FieldPosition.
|
||||
*/
|
||||
private static final FieldPosition HELPER_POSITION = new FieldPosition(0);
|
||||
|
||||
/**
|
||||
* This Format for format the number to special format.
|
||||
*/
|
||||
private final static NumberFormat numberFormat = new DecimalFormat("00000000");
|
||||
|
||||
/**
|
||||
* This int is the sequence number ,the default value is 1.
|
||||
*/
|
||||
private static AtomicInteger seq = new AtomicInteger(1);
|
||||
|
||||
private static final int MAX = 99999999;
|
||||
|
||||
private BizSequenceUtils() {
|
||||
}
|
||||
|
||||
public static BizSequenceUtils getInstance() {
|
||||
if (instance == null) {
|
||||
synchronized (lock) {
|
||||
if (instance == null) {
|
||||
instance = new BizSequenceUtils();
|
||||
}
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* 生成业务流水号(唯一标示一笔业务)
|
||||
*
|
||||
* @param bizSeqNoPrefix 业务前缀(2字符,参见Constant.**_BIZ_SEQUENCE_NO_PREFIX)
|
||||
* @return
|
||||
*/
|
||||
public String generateBizSeqNo(String bizSeqNoPrefix) {
|
||||
StringBuffer bizSeqNo = new StringBuffer();
|
||||
bizSeqNo.append(bizSeqNoPrefix)
|
||||
.append(DateUtils.getCurrentTimeStr("yyMMddHHmmss"))
|
||||
.append(getSeq());
|
||||
return bizSeqNo.toString();
|
||||
}
|
||||
|
||||
private String getSeq() {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
numberFormat.format(seq, sb, HELPER_POSITION);
|
||||
if (!seq.compareAndSet(MAX, 0)) {
|
||||
seq.incrementAndGet();
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package org.xxpay.common.util;
|
||||
|
||||
import org.apache.commons.beanutils.Converter;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.text.DateFormatSymbols;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by admin on 2016/5/10.
|
||||
*/
|
||||
public class DateTimeConverter implements Converter {
|
||||
|
||||
private static final String DATE = "yyyy-MM-dd";
|
||||
private static final String DATETIME = "yyyy-MM-dd HH:mm:ss";
|
||||
private static final String TIMESTAMP = "yyyy-MM-dd HH:mm:ss.SSS";
|
||||
|
||||
@Override
|
||||
public Object convert(Class type, Object value) {
|
||||
return toDate(type, value);
|
||||
}
|
||||
|
||||
public static Object toDate(Class type, Object value) {
|
||||
if (value == null || "".equals(value))
|
||||
return null;
|
||||
if (value instanceof String) {
|
||||
String dateValue = value.toString().trim();
|
||||
int length = dateValue.length();
|
||||
if (type.equals(java.util.Date.class)) {
|
||||
try {
|
||||
DateFormat formatter = null;
|
||||
if (length <= 10) {
|
||||
formatter = new SimpleDateFormat(DATE, new DateFormatSymbols(Locale.CHINA));
|
||||
return formatter.parse(dateValue);
|
||||
}
|
||||
if (length <= 19) {
|
||||
formatter = new SimpleDateFormat(DATETIME, new DateFormatSymbols(Locale.CHINA));
|
||||
return formatter.parse(dateValue);
|
||||
}
|
||||
if (length <= 23) {
|
||||
formatter = new SimpleDateFormat(TIMESTAMP, new DateFormatSymbols(Locale.CHINA));
|
||||
return formatter.parse(dateValue);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,70 @@
|
|||
package org.xxpay.common.util;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* 时间格式化工具
|
||||
* Created by admin on 2016/5/4.
|
||||
*/
|
||||
public class DateUtils {
|
||||
|
||||
private static final String DEFAULT_CONVERT_PATTERN = "yyyyMMddHHmmssSSS";
|
||||
|
||||
/**
|
||||
* 获取当前时间字符串(默认格式:yyyyMMddHHmmssSSS)
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public static String getCurrentTimeStrDefault() {
|
||||
return getCurrentTimeStr(DEFAULT_CONVERT_PATTERN);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定时间字符串(默认格式:yyyyMMddHHmmssSSS)
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static String getTimeStrDefault(Date date) {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_CONVERT_PATTERN);
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当前时间字符串
|
||||
*
|
||||
* @param pattern 转换格式
|
||||
* @return
|
||||
*/
|
||||
public static String getCurrentTimeStr(String pattern) {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
|
||||
return dateFormat.format(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定时间字符串
|
||||
* @param date
|
||||
* @return
|
||||
*/
|
||||
public static String getTimeStr(Date date, String pattern) {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(pattern);
|
||||
return dateFormat.format(date);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断时间字符串是否为默认格式
|
||||
* @param dateTimeStr
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValidDefaultFormat(String dateTimeStr) {
|
||||
SimpleDateFormat dateFormat = new SimpleDateFormat(DEFAULT_CONVERT_PATTERN);
|
||||
try {
|
||||
dateFormat.parse(dateTimeStr);
|
||||
return true;
|
||||
} catch (Exception e) {
|
||||
// 如果抛出异常,说明格式不正确
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,52 @@
|
|||
package org.xxpay.common.util;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by admin on 2016/4/13.
|
||||
*/
|
||||
public class JsonUtil {
|
||||
|
||||
static {
|
||||
System.setProperty("fastjson.compatibleWithJavaBean", "true");
|
||||
}
|
||||
|
||||
public static String object2Json(Object object) {
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
return JSONObject.toJSONString(object);
|
||||
}
|
||||
|
||||
public static <T> T getObjectFromJson(String json, Class<T> clazz) {
|
||||
if (json == null) {
|
||||
return null;
|
||||
}
|
||||
return JSON.parseObject(json, clazz);
|
||||
}
|
||||
|
||||
public static <T> List<T> getObjectListFromJson(String json, Class<T> clazz) {
|
||||
if (json == null) {
|
||||
return null;
|
||||
}
|
||||
return JSON.parseArray(json, clazz);
|
||||
}
|
||||
|
||||
public static JSONObject getJSONObjectFromJson(String json) {
|
||||
if (json == null) {
|
||||
return null;
|
||||
}
|
||||
return JSONObject.parseObject(json);
|
||||
}
|
||||
|
||||
public static JSONObject getJSONObjectFromObj(Object object) {
|
||||
if (object == null) {
|
||||
return null;
|
||||
}
|
||||
return (JSONObject) JSONObject.toJSON(object);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,230 @@
|
|||
package org.xxpay.common.util;
|
||||
|
||||
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by admin on 2016/6/23.
|
||||
*/
|
||||
public class ObjectValidUtil {
|
||||
|
||||
public static boolean isValid(Object... objs) {
|
||||
if (objs == null || objs.length < 1) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (Object obj : objs) {
|
||||
if (obj instanceof Short) {
|
||||
if (isNull(obj)) {
|
||||
return false;
|
||||
}
|
||||
} else if (obj instanceof Integer) {
|
||||
if (isInvalidInteger((Integer) obj)) {
|
||||
return false;
|
||||
}
|
||||
} else if (obj instanceof Long) {
|
||||
if (isInvalidLong((Long) obj)) {
|
||||
return false;
|
||||
}
|
||||
} else if (obj instanceof String) {
|
||||
if (isInvalidString(obj.toString())) {
|
||||
return false;
|
||||
}
|
||||
} else if (obj instanceof List) {
|
||||
if (CollectionUtils.isEmpty((List) obj)) {
|
||||
return false;
|
||||
}
|
||||
} else if (obj instanceof Map) {
|
||||
if (isNull(obj) || ((Map) obj).isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
if (isNull(obj)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isInvalid(Object... objs) {
|
||||
return !isValid(objs);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为有效Short值
|
||||
* @param num
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValidShort(Short num) {
|
||||
if (num == null || num.compareTo((short) 0) <= 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isInvalidShort(Short num) {
|
||||
return !isValidShort(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为有效Integer值
|
||||
* @param num
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValidInteger(Integer num) {
|
||||
if (num == null || num.compareTo(0) <= 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isInvalidInteger(Integer num) {
|
||||
return !isValidInteger(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为有效Long值
|
||||
* @param num
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValidLong(Long num) {
|
||||
if (num == null || num.compareTo(0L) <= 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isInvalidLong(Long num) {
|
||||
return !isValidLong(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为有效BigDecimal值
|
||||
* @param num
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValidBigDecimal(BigDecimal num) {
|
||||
if (num == null || num.compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isInvalidBigDecimal(BigDecimal num) {
|
||||
return !isValidBigDecimal(num);
|
||||
}
|
||||
|
||||
/**
|
||||
* 判断是否为有效String值
|
||||
* @param str
|
||||
* @return
|
||||
*/
|
||||
public static boolean isValidString(String str) {
|
||||
return StringUtils.isNotBlank(str);
|
||||
}
|
||||
|
||||
public static boolean isInvalidString(String str) {
|
||||
return StringUtils.isBlank(str);
|
||||
}
|
||||
|
||||
public static boolean isNull(Object obj) {
|
||||
if (obj == null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static boolean isNotNull(Object obj) {
|
||||
return !isNull(obj);
|
||||
}
|
||||
|
||||
public static boolean isValidCurPage(Integer curPage) {
|
||||
if (curPage == null) {
|
||||
return false;
|
||||
}
|
||||
if (curPage.compareTo(1) < 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isValidCurPage(Long curPage) {
|
||||
if (curPage == null) {
|
||||
return false;
|
||||
}
|
||||
if (curPage.compareTo(1L) < 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isInvalidCurPage(Integer curPage) {
|
||||
return !isValidCurPage(curPage);
|
||||
}
|
||||
|
||||
public static boolean isInvalidCurPage(Long curPage) {
|
||||
return !isValidCurPage(curPage);
|
||||
}
|
||||
|
||||
public static boolean isValidViewNumber(Integer viewNumber) {
|
||||
if (viewNumber == null) {
|
||||
return false;
|
||||
}
|
||||
if (viewNumber.compareTo(0) <= 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isValidViewNumber(Long viewNumber) {
|
||||
if (viewNumber == null) {
|
||||
return false;
|
||||
}
|
||||
if (viewNumber.compareTo(0L) <= 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isInvalidViewNumber(Integer viewNumber) {
|
||||
return !isValidViewNumber(viewNumber);
|
||||
}
|
||||
|
||||
public static boolean isInvalidViewNumber(Long viewNumber) {
|
||||
return !isValidViewNumber(viewNumber);
|
||||
}
|
||||
|
||||
public static boolean isValidLimit(Integer limit) {
|
||||
if (limit == null) {
|
||||
return false;
|
||||
}
|
||||
if (limit.compareTo(0) <= 0) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean isInvalidLimit(Integer limit) {
|
||||
return !isValidLimit(limit);
|
||||
}
|
||||
|
||||
public static boolean isAllNull(Object... objs) {
|
||||
if (objs == null || objs.length < 1) {
|
||||
return true;
|
||||
}
|
||||
int nullcount = 0;
|
||||
for (Object obj : objs) {
|
||||
if (isNull(obj)) {
|
||||
nullcount++;
|
||||
}
|
||||
}
|
||||
return objs.length == nullcount;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,90 @@
|
|||
package org.xxpay.common.util;
|
||||
|
||||
import org.xxpay.common.constant.Constant;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
/**
|
||||
* 生成随机通讯码工具类
|
||||
* Created by admin on 2016/5/4.
|
||||
*/
|
||||
public class RandomStrUtils {
|
||||
|
||||
private static Object lock = new Object();
|
||||
|
||||
private static RandomStrUtils instance;
|
||||
|
||||
private Map<String, Long> randomStrMap = new ConcurrentHashMap<String, Long>();
|
||||
|
||||
private static final String[] BASE_STRING = new String[]{
|
||||
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
|
||||
"a", "b", "c", "d", "e", "f", "g", "h", "i", "j",
|
||||
"k", "l", "m", "n", "o", "p", "q", "r", "s", "t",
|
||||
"u", "v", "w", "x", "y", "z", "A", "B", "C", "D",
|
||||
"E", "F", "G", "H", "I", "J", "K", "L", "M", "N",
|
||||
"O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z"
|
||||
};
|
||||
|
||||
private static final int RANDOM_STRING_LENGTH = 6;
|
||||
|
||||
private RandomStrUtils() {
|
||||
}
|
||||
|
||||
public static RandomStrUtils getInstance() {
|
||||
synchronized (lock) {
|
||||
if (instance == null) {
|
||||
instance = new RandomStrUtils();
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public String getRandomString() {
|
||||
Long nowTime = System.currentTimeMillis();
|
||||
String randomStr = null;
|
||||
|
||||
synchronized (lock) {
|
||||
// 生成随机字符串
|
||||
randomStr = createRandomString(RANDOM_STRING_LENGTH, nowTime);
|
||||
|
||||
// 删除一分钟前的随机字符串
|
||||
Iterator<Map.Entry<String, Long>> it = randomStrMap.entrySet().iterator();
|
||||
while (it.hasNext()) {
|
||||
Map.Entry<String, Long> entry = it.next();
|
||||
Long value = entry.getValue();
|
||||
if (nowTime - value > Constant.RPC_SEQ_NO_NOT_REPEAT_INTERVAL) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return randomStr;
|
||||
}
|
||||
|
||||
private String createRandomString(int len, Long nowTime) {
|
||||
Random random = new Random();
|
||||
int length = BASE_STRING.length;
|
||||
String randomString = "";
|
||||
for (int i = 0; i < length; i++) {
|
||||
randomString += BASE_STRING[random.nextInt(length)];
|
||||
}
|
||||
random = new Random(System.currentTimeMillis());
|
||||
String resultStr = "";
|
||||
for (int i = 0; i < len; i++) {
|
||||
resultStr += randomString.charAt(random.nextInt(randomString.length() - 1));
|
||||
}
|
||||
|
||||
// 判断一分钟内是否重复
|
||||
Long randomStrCreateTime = randomStrMap.get(resultStr);
|
||||
if (randomStrCreateTime != null &&
|
||||
nowTime - randomStrCreateTime < Constant.RPC_SEQ_NO_NOT_REPEAT_INTERVAL) {
|
||||
resultStr = createRandomString(len, nowTime);
|
||||
}
|
||||
randomStrMap.put(resultStr, nowTime);
|
||||
return resultStr;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package org.xxpay.common.util;
|
||||
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
/**
|
||||
* RPC通讯层签名工具类
|
||||
* Created by admin on 2016/5/3.
|
||||
*/
|
||||
public class RpcSignUtils {
|
||||
|
||||
public static String sha1(String decript) {
|
||||
try {
|
||||
MessageDigest digest = MessageDigest
|
||||
.getInstance("SHA-1");
|
||||
digest.update(decript.getBytes());
|
||||
byte messageDigest[] = digest.digest();
|
||||
// Create Hex String
|
||||
StringBuffer hexString = new StringBuffer();
|
||||
// 字节数组转换为 十六进制 数
|
||||
for (int i = 0; i < messageDigest.length; i++) {
|
||||
String shaHex = Integer.toHexString(messageDigest[i] & 0xFF);
|
||||
if (shaHex.length() < 2) {
|
||||
hexString.append(0);
|
||||
}
|
||||
hexString.append(shaHex);
|
||||
}
|
||||
return hexString.toString();
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
package org.xxpay.common.util;
|
||||
|
||||
import org.xxpay.common.constant.Constant;
|
||||
import org.xxpay.common.domain.BaseParam;
|
||||
import org.xxpay.common.domain.RpcBaseParam;
|
||||
import org.xxpay.common.enumm.RetEnum;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/9
|
||||
* @description:
|
||||
*/
|
||||
public class RpcUtil {
|
||||
|
||||
public static BaseParam getBaseParam(Map<String, Object> paramMap) {
|
||||
if (paramMap == null || paramMap.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
BaseParam baseParam = BeanConvertUtils.map2Bean(paramMap, BaseParam.class);
|
||||
paramMap.remove("rpcSrcSysId");
|
||||
paramMap.remove("rpcDateTime");
|
||||
paramMap.remove("rpcSeqNo");
|
||||
paramMap.remove("rpcSignType");
|
||||
paramMap.remove("rpcSign");
|
||||
paramMap.remove("bizSeqNo");
|
||||
paramMap.remove("bizSign");
|
||||
baseParam.setBizParamMap(paramMap);
|
||||
return baseParam;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建成功返回结果
|
||||
* @param baseParam
|
||||
* @param obj
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, Object> createBizResult(RpcBaseParam baseParam, Object obj) {
|
||||
Map<String, Object> resultMap = createResultMap(baseParam, RetEnum.RET_SUCCESS);
|
||||
resultMap.put(Constant.BIZ_RESULT_KEY, obj);
|
||||
return resultMap;
|
||||
}
|
||||
public static Map<String, Object> createBizResultWithDBError(RpcBaseParam baseParam, Object obj,
|
||||
String dbErrorCode, String dbErrorMsg) {
|
||||
Map<String, Object> resultMap = createResultMapWithDBError(baseParam, RetEnum.RET_SUCCESS, dbErrorCode, dbErrorMsg);
|
||||
resultMap.put(Constant.BIZ_RESULT_KEY, obj);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建失败返回结果
|
||||
* @param rpcBaseParam
|
||||
* @param retEnum
|
||||
* @return
|
||||
*/
|
||||
public static Map<String, Object> createFailResult(RpcBaseParam rpcBaseParam, RetEnum retEnum) {
|
||||
if (retEnum == null) {
|
||||
retEnum = RetEnum.RET_PARAM_NOT_FOUND;
|
||||
}
|
||||
return createResultMap(rpcBaseParam, retEnum);
|
||||
}
|
||||
|
||||
public static Map<String, Object> createFailResultWithDBError(RpcBaseParam rpcBaseParam, RetEnum retEnum,
|
||||
String dbErrorCode, String dbErrorMsg) {
|
||||
if (retEnum == null) {
|
||||
retEnum = RetEnum.RET_PARAM_NOT_FOUND;
|
||||
}
|
||||
return createResultMapWithDBError(rpcBaseParam, retEnum, dbErrorCode, dbErrorMsg);
|
||||
}
|
||||
|
||||
private static Map<String, Object> createResultMap(RpcBaseParam rpcBaseParam, RetEnum retEnum) {
|
||||
Map<String, Object> resultMap = null;
|
||||
if (rpcBaseParam != null) {
|
||||
resultMap = rpcBaseParam.convert2Map();
|
||||
} else {
|
||||
resultMap = new HashMap<String, Object>();
|
||||
}
|
||||
resultMap.put("rpcRetCode", retEnum.getCode());
|
||||
resultMap.put("rpcRetMsg", retEnum.getMessage());
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
private static Map<String, Object> createResultMapWithDBError(RpcBaseParam rpcBaseParam, RetEnum retEnum,
|
||||
String dbErrorCode, String dbErrorMsg) {
|
||||
Map<String, Object> resultMap = null;
|
||||
if (rpcBaseParam != null) {
|
||||
resultMap = rpcBaseParam.convert2Map();
|
||||
} else {
|
||||
resultMap = new HashMap<String, Object>();
|
||||
}
|
||||
resultMap.put("rpcRetCode", retEnum.getCode());
|
||||
resultMap.put("rpcRetMsg", retEnum.getMessage());
|
||||
resultMap.put("dbErrorCode", dbErrorCode);
|
||||
resultMap.put("dbErrorMsg", dbErrorMsg);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
public static String createBaseParam(Map<String, Object> paramMap) {
|
||||
BaseParam baseParam = new BaseParam("102", "rpc-src-sys-vvlive-config-key", Constant.CF_BIZ_SEQUENCE_NO_PREFIX);
|
||||
baseParam.setBizParamMap(paramMap);
|
||||
return baseParam.toJson();
|
||||
}
|
||||
|
||||
public static String mkRet(Map<String, Object> result) {
|
||||
//_log.info("调用dal返回result={}", result);
|
||||
if(result == null) return null;
|
||||
String retCode = (String)result.get("rpcRetCode");
|
||||
if("0000".equals(retCode)) {
|
||||
if(result.get("bizResult") == null) return null;
|
||||
return result.get("bizResult").toString();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,48 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.xxpay</groupId>
|
||||
<artifactId>xxpay4dubbo</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
<name>xxpay4dubbo</name>
|
||||
<description>xxpay4dubbo</description>
|
||||
|
||||
<modules>
|
||||
<module>xxpay4dubbo-api</module>
|
||||
<module>xxpay4dubbo-web</module>
|
||||
<module>xxpay4dubbo-service</module>
|
||||
</modules>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>1.5.6.RELEASE</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||
<java.version>1.8</java.version>
|
||||
<springboot.version>1.5.6.RELEASE</springboot.version>
|
||||
<springboot.dubbo.version>1.5.6.RELEASE</springboot.dubbo.version>
|
||||
</properties>
|
||||
|
||||
<dependencyManagement>
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>io.dubbo.springboot</groupId>
|
||||
<artifactId>spring-boot-starter-dubbo</artifactId>
|
||||
<version>${springboot.dubbo.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
<version>${springboot.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</dependencyManagement>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.xxpay</groupId>
|
||||
<artifactId>xxpay4dubbo-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>xxpay4dubbo-api</name>
|
||||
<description>xxpay4dubbo-api</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.xxpay</groupId>
|
||||
<artifactId>xxpay4dubbo</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<properties>
|
||||
<commons.beanutils.version>1.7.0</commons.beanutils.version>
|
||||
</properties>
|
||||
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.xxpay</groupId>
|
||||
<artifactId>xxpay-common</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package org.xxpay.dubbo.api.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/8
|
||||
* @description:
|
||||
*/
|
||||
public interface IMchInfoService {
|
||||
|
||||
public Map selectMchInfo(String jsonParam);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
package org.xxpay.dubbo.api.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/10
|
||||
* @description:
|
||||
*/
|
||||
public interface INotifyPayService {
|
||||
|
||||
Map doAliPayNotify(String jsonParam);
|
||||
|
||||
Map doWxPayNotify(String jsonParam);
|
||||
|
||||
Map sendBizPayNotify(String jsonParam);
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
package org.xxpay.dubbo.api.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/10
|
||||
* @description:
|
||||
*/
|
||||
public interface IPayChannel4AliService {
|
||||
|
||||
Map doAliPayWapReq(String jsonParam);
|
||||
|
||||
Map doAliPayPcReq(String jsonParam);
|
||||
|
||||
Map doAliPayMobileReq(String jsonParam);
|
||||
|
||||
Map doAliPayQrReq(String jsonParam);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package org.xxpay.dubbo.api.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/9
|
||||
* @description:
|
||||
*/
|
||||
public interface IPayChannel4WxService {
|
||||
|
||||
Map doWxPayReq(String jsonParam);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,14 @@
|
|||
package org.xxpay.dubbo.api.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/8
|
||||
* @description:
|
||||
*/
|
||||
public interface IPayChannelService {
|
||||
|
||||
public Map selectPayChannel(String jsonParam);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
package org.xxpay.dubbo.api.service;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/8
|
||||
* @description:
|
||||
*/
|
||||
public interface IPayOrderService {
|
||||
|
||||
public Map createPayOrder(String jsonParam);
|
||||
|
||||
public Map selectPayOrder(String jsonParam);
|
||||
|
||||
public Map selectPayOrderByMchIdAndPayOrderId(String jsonParam);
|
||||
|
||||
public Map selectPayOrderByMchIdAndMchOrderNo(String jsonParam);
|
||||
|
||||
public Map updateStatus4Ing(String jsonParam);
|
||||
|
||||
public Map updateStatus4Success(String jsonParam);
|
||||
|
||||
public Map updateStatus4Complete(String jsonParam);
|
||||
|
||||
public Map updateNotify(String jsonParam);
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,72 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.xxpay</groupId>
|
||||
<artifactId>xxpay4dubbo-service</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>xxpay4dubbo-service</name>
|
||||
<description>xxpay4dubbo-service</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.xxpay</groupId>
|
||||
<artifactId>xxpay4dubbo</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.xxpay</groupId>
|
||||
<artifactId>xxpay4dubbo-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.xxpay</groupId>
|
||||
<artifactId>xxpay-dal</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dubbo.springboot</groupId>
|
||||
<artifactId>spring-boot-starter-dubbo</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-activemq</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mybatis.spring.boot</groupId>
|
||||
<artifactId>mybatis-spring-boot-starter</artifactId>
|
||||
<version>1.3.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-configuration-processor</artifactId>
|
||||
</dependency>
|
||||
<!--wx_pay-->
|
||||
<dependency>
|
||||
<groupId>com.github.binarywang</groupId>
|
||||
<artifactId>weixin-java-pay</artifactId>
|
||||
<version>2.8.0</version>
|
||||
</dependency>
|
||||
<!--ali_pay-->
|
||||
<dependency>
|
||||
<groupId>com.alipay</groupId>
|
||||
<artifactId>sdk</artifactId>
|
||||
<version>1.5</version>
|
||||
<scope>system</scope>
|
||||
<systemPath>${basedir}/src/main/webapp/WEB-INF/lib/alipay-sdk-java20170818173712.jar</systemPath>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${springboot.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package org.xxpay.dubbo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages={"org.xxpay"})
|
||||
public class XxPayDubboServiceAppliaction {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(XxPayDubboServiceAppliaction.class, args);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,119 @@
|
|||
package org.xxpay.dubbo.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.xxpay.common.constant.PayConstant;
|
||||
import org.xxpay.dal.dao.mapper.MchInfoMapper;
|
||||
import org.xxpay.dal.dao.mapper.PayChannelMapper;
|
||||
import org.xxpay.dal.dao.mapper.PayOrderMapper;
|
||||
import org.xxpay.dal.dao.model.*;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/9
|
||||
* @description:
|
||||
*/
|
||||
@Service
|
||||
public class BaseService {
|
||||
|
||||
@Autowired
|
||||
private PayOrderMapper payOrderMapper;
|
||||
|
||||
@Autowired
|
||||
private MchInfoMapper mchInfoMapper;
|
||||
|
||||
@Autowired
|
||||
private PayChannelMapper payChannelMapper;
|
||||
|
||||
|
||||
public MchInfo baseSelectMchInfo(String mchId) {
|
||||
return mchInfoMapper.selectByPrimaryKey(mchId);
|
||||
}
|
||||
|
||||
public PayChannel baseSelectPayChannel(String mchId, String channelId) {
|
||||
PayChannelExample example = new PayChannelExample();
|
||||
PayChannelExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andChannelIdEqualTo(channelId);
|
||||
criteria.andMchIdEqualTo(mchId);
|
||||
List<PayChannel> payChannelList = payChannelMapper.selectByExample(example);
|
||||
if(CollectionUtils.isEmpty(payChannelList)) return null;
|
||||
return payChannelList.get(0);
|
||||
}
|
||||
|
||||
public int baseCreatePayOrder(PayOrder payOrder) {
|
||||
return payOrderMapper.insertSelective(payOrder);
|
||||
}
|
||||
|
||||
public PayOrder baseSelectPayOrder(String payOrderId) {
|
||||
return payOrderMapper.selectByPrimaryKey(payOrderId);
|
||||
}
|
||||
|
||||
public PayOrder baseSelectPayOrderByMchIdAndPayOrderId(String mchId, String payOrderId) {
|
||||
PayOrderExample example = new PayOrderExample();
|
||||
PayOrderExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andMchIdEqualTo(mchId);
|
||||
criteria.andPayOrderIdEqualTo(payOrderId);
|
||||
List<PayOrder> payOrderList = payOrderMapper.selectByExample(example);
|
||||
return CollectionUtils.isEmpty(payOrderList) ? null : payOrderList.get(0);
|
||||
}
|
||||
|
||||
public PayOrder baseSelectPayOrderByMchIdAndMchOrderNo(String mchId, String mchOrderNo) {
|
||||
PayOrderExample example = new PayOrderExample();
|
||||
PayOrderExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andMchIdEqualTo(mchId);
|
||||
criteria.andMchOrderNoEqualTo(mchOrderNo);
|
||||
List<PayOrder> payOrderList = payOrderMapper.selectByExample(example);
|
||||
return CollectionUtils.isEmpty(payOrderList) ? null : payOrderList.get(0);
|
||||
}
|
||||
|
||||
public int baseUpdateStatus4Ing(String payOrderId, String channelOrderNo) {
|
||||
PayOrder payOrder = new PayOrder();
|
||||
payOrder.setStatus(PayConstant.PAY_STATUS_PAYING);
|
||||
if(channelOrderNo != null) payOrder.setChannelOrderNo(channelOrderNo);
|
||||
payOrder.setPaySuccTime(System.currentTimeMillis());
|
||||
PayOrderExample example = new PayOrderExample();
|
||||
PayOrderExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andPayOrderIdEqualTo(payOrderId);
|
||||
criteria.andStatusEqualTo(PayConstant.PAY_STATUS_INIT);
|
||||
return payOrderMapper.updateByExampleSelective(payOrder, example);
|
||||
}
|
||||
|
||||
public int baseUpdateStatus4Success(String payOrderId) {
|
||||
PayOrder payOrder = new PayOrder();
|
||||
payOrder.setPayOrderId(payOrderId);
|
||||
payOrder.setStatus(PayConstant.PAY_STATUS_SUCCESS);
|
||||
payOrder.setPaySuccTime(System.currentTimeMillis());
|
||||
PayOrderExample example = new PayOrderExample();
|
||||
PayOrderExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andPayOrderIdEqualTo(payOrderId);
|
||||
criteria.andStatusEqualTo(PayConstant.PAY_STATUS_PAYING);
|
||||
return payOrderMapper.updateByExampleSelective(payOrder, example);
|
||||
}
|
||||
|
||||
public int baseUpdateStatus4Complete(String payOrderId) {
|
||||
PayOrder payOrder = new PayOrder();
|
||||
payOrder.setPayOrderId(payOrderId);
|
||||
payOrder.setStatus(PayConstant.PAY_STATUS_COMPLETE);
|
||||
PayOrderExample example = new PayOrderExample();
|
||||
PayOrderExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andPayOrderIdEqualTo(payOrderId);
|
||||
criteria.andStatusEqualTo(PayConstant.PAY_STATUS_SUCCESS);
|
||||
return payOrderMapper.updateByExampleSelective(payOrder, example);
|
||||
}
|
||||
|
||||
public int baseUpdateNotify(String payOrderId, byte count) {
|
||||
PayOrder newPayOrder = new PayOrder();
|
||||
newPayOrder.setNotifyCount(count);
|
||||
newPayOrder.setLastNotifyTime(System.currentTimeMillis());
|
||||
newPayOrder.setPayOrderId(payOrderId);
|
||||
return payOrderMapper.updateByPrimaryKeySelective(newPayOrder);
|
||||
}
|
||||
|
||||
public int baseUpdateNotify(PayOrder payOrder) {
|
||||
return payOrderMapper.updateByPrimaryKeySelective(payOrder);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,120 @@
|
|||
package org.xxpay.dubbo.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.xxpay.common.constant.PayConstant;
|
||||
import org.xxpay.common.util.MyLog;
|
||||
import org.xxpay.common.util.PayDigestUtil;
|
||||
import org.xxpay.common.util.XXPayUtil;
|
||||
import org.xxpay.dal.dao.model.MchInfo;
|
||||
import org.xxpay.dal.dao.model.PayOrder;
|
||||
import org.xxpay.dubbo.service.mq.Mq4PayNotify;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 支付通知处理基类
|
||||
* @author dingzhiwei jmdhappy@126.com
|
||||
* @date 2017-07-05
|
||||
* @version V1.0
|
||||
* @Copyright: www.xxpay.org
|
||||
*/
|
||||
@Component
|
||||
public class Notify4BasePay extends BaseService {
|
||||
|
||||
private static final MyLog _log = MyLog.getLog(Notify4BasePay.class);
|
||||
|
||||
@Autowired
|
||||
private Mq4PayNotify mq4PayNotify;
|
||||
|
||||
/**
|
||||
* 创建响应URL
|
||||
* @param payOrder
|
||||
* @param backType 1:前台页面;2:后台接口
|
||||
* @return
|
||||
*/
|
||||
public String createNotifyUrl(PayOrder payOrder, String backType) {
|
||||
String mchId = payOrder.getMchId();
|
||||
MchInfo mchInfo = super.baseSelectMchInfo(mchId);
|
||||
String resKey = mchInfo.getResKey();
|
||||
Map<String, Object> paramMap = new HashMap<>();
|
||||
paramMap.put("payOrderId", payOrder.getPayOrderId() == null ? "" : payOrder.getPayOrderId()); // 支付订单号
|
||||
paramMap.put("mchId", payOrder.getMchId() == null ? "" : payOrder.getMchId()); // 商户ID
|
||||
paramMap.put("mchOrderNo", payOrder.getMchOrderNo() == null ? "" : payOrder.getMchOrderNo()); // 商户订单号
|
||||
paramMap.put("channelId", payOrder.getChannelId() == null ? "" : payOrder.getChannelId()); // 渠道ID
|
||||
paramMap.put("amount", payOrder.getAmount() == null ? "" : payOrder.getAmount()); // 支付金额
|
||||
paramMap.put("currency", payOrder.getCurrency() == null ? "" : payOrder.getCurrency()); // 货币类型
|
||||
paramMap.put("status", payOrder.getStatus() == null ? "" : payOrder.getStatus()); // 支付状态
|
||||
paramMap.put("clientIp", payOrder.getClientIp()==null ? "" : payOrder.getClientIp()); // 客户端IP
|
||||
paramMap.put("device", payOrder.getDevice()==null ? "" : payOrder.getDevice()); // 设备
|
||||
paramMap.put("subject", payOrder.getSubject()==null ? "" : payOrder.getSubject()); // 商品标题
|
||||
paramMap.put("channelOrderNo", payOrder.getChannelOrderNo()==null ? "" : payOrder.getChannelOrderNo()); // 渠道订单号
|
||||
paramMap.put("param1", payOrder.getParam1()==null ? "" : payOrder.getParam1()); // 扩展参数1
|
||||
paramMap.put("param2", payOrder.getParam2()==null ? "" : payOrder.getParam2()); // 扩展参数2
|
||||
paramMap.put("paySuccTime", payOrder.getPaySuccTime()==null ? "" : payOrder.getPaySuccTime()); // 支付成功时间
|
||||
paramMap.put("backType", backType==null ? "" : backType);
|
||||
// 先对原文签名
|
||||
String reqSign = PayDigestUtil.getSign(paramMap, resKey);
|
||||
paramMap.put("sign", reqSign); // 签名
|
||||
// 签名后再对有中文参数编码
|
||||
try {
|
||||
paramMap.put("device", URLEncoder.encode(payOrder.getDevice()==null ? "" : payOrder.getDevice(), PayConstant.RESP_UTF8));
|
||||
paramMap.put("subject", URLEncoder.encode(payOrder.getSubject()==null ? "" : payOrder.getSubject(), PayConstant.RESP_UTF8));
|
||||
paramMap.put("param1", URLEncoder.encode(payOrder.getParam1()==null ? "" : payOrder.getParam1(), PayConstant.RESP_UTF8));
|
||||
paramMap.put("param2", URLEncoder.encode(payOrder.getParam2()==null ? "" : payOrder.getParam2(), PayConstant.RESP_UTF8));
|
||||
}catch (UnsupportedEncodingException e) {
|
||||
_log.error("URL Encode exception.", e);
|
||||
return null;
|
||||
}
|
||||
String param = XXPayUtil.genUrlParams(paramMap);
|
||||
StringBuffer sb = new StringBuffer();
|
||||
sb.append(payOrder.getNotifyUrl()).append("?").append(param);
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理支付结果前台页面跳转
|
||||
*/
|
||||
public boolean doPage(PayOrder payOrder) {
|
||||
String redirectUrl = createNotifyUrl(payOrder, "1");
|
||||
_log.info("redirect to respUrl:"+redirectUrl);
|
||||
// 前台跳转业务系统
|
||||
/*try {
|
||||
response.sendRedirect(redirectUrl);
|
||||
} catch (IOException e) {
|
||||
_log.error("XxPay sendRedirect exception. respUrl="+redirectUrl, e);
|
||||
return false;
|
||||
}*/
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 处理支付结果后台服务器通知
|
||||
*/
|
||||
public void doNotify(PayOrder payOrder) {
|
||||
_log.info(">>>>>> PAY开始回调通知业务系统 <<<<<<");
|
||||
// 发起后台通知业务系统
|
||||
JSONObject object = createNotifyInfo(payOrder);
|
||||
try {
|
||||
mq4PayNotify.send(object.toJSONString());
|
||||
} catch (Exception e) {
|
||||
_log.error("payOrderId={},sendMessage error.", payOrder != null ? payOrder.getPayOrderId() : "", e);
|
||||
}
|
||||
_log.info(">>>>>> PAY回调通知业务系统完成 <<<<<<");
|
||||
}
|
||||
|
||||
public JSONObject createNotifyInfo(PayOrder payOrder) {
|
||||
JSONObject object = new JSONObject();
|
||||
object.put("method", "GET");
|
||||
object.put("url", createNotifyUrl(payOrder, "2"));
|
||||
object.put("orderId", payOrder.getPayOrderId());
|
||||
object.put("count", payOrder.getNotifyCount());
|
||||
object.put("createTime", System.currentTimeMillis());
|
||||
return object;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,117 @@
|
|||
package org.xxpay.dubbo.service.channel.alipay;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/8/21
|
||||
* @description:
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix="config.ali")
|
||||
public class AlipayConfig {
|
||||
|
||||
// 商户appid
|
||||
private String app_id;
|
||||
// 私钥 pkcs8格式的
|
||||
private String rsa_private_key;
|
||||
// 服务器异步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问
|
||||
|
||||
private String notify_url;
|
||||
// 页面跳转同步通知页面路径 需http://或者https://格式的完整路径,不能加?id=123这类自定义参数,必须外网可以正常访问 商户可以自定义同步跳转地址
|
||||
|
||||
private String return_url;
|
||||
// 请求网关地址
|
||||
private String url = "https://openapi.alipay.com/gateway.do";
|
||||
|
||||
// 编码
|
||||
public static String CHARSET = "UTF-8";
|
||||
// 返回格式
|
||||
public static String FORMAT = "json";
|
||||
// 支付宝公钥
|
||||
public String alipay_public_key;
|
||||
// RSA2
|
||||
public static String SIGNTYPE = "RSA2";
|
||||
|
||||
// 是否沙箱环境,1:沙箱,0:正式环境
|
||||
private Short isSandbox = 0;
|
||||
|
||||
/**
|
||||
* 初始化支付宝配置
|
||||
* @param configParam
|
||||
* @return
|
||||
*/
|
||||
public AlipayConfig init(String configParam) {
|
||||
Assert.notNull(configParam, "init alipay config error");
|
||||
JSONObject paramObj = JSON.parseObject(configParam);
|
||||
this.setApp_id(paramObj.getString("appid"));
|
||||
this.setRsa_private_key(paramObj.getString("private_key"));
|
||||
this.setAlipay_public_key(paramObj.getString("alipay_public_key"));
|
||||
this.setIsSandbox(paramObj.getShortValue("isSandbox"));
|
||||
if(this.getIsSandbox() == 1) this.setUrl("https://openapi.alipaydev.com/gateway.do");
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getApp_id() {
|
||||
return app_id;
|
||||
}
|
||||
|
||||
public void setApp_id(String app_id) {
|
||||
this.app_id = app_id;
|
||||
}
|
||||
|
||||
public String getRsa_private_key() {
|
||||
return rsa_private_key;
|
||||
}
|
||||
|
||||
public void setRsa_private_key(String rsa_private_key) {
|
||||
this.rsa_private_key = rsa_private_key;
|
||||
}
|
||||
|
||||
public String getNotify_url() {
|
||||
return notify_url;
|
||||
}
|
||||
|
||||
public void setNotify_url(String notify_url) {
|
||||
this.notify_url = notify_url;
|
||||
}
|
||||
|
||||
public String getReturn_url() {
|
||||
return return_url;
|
||||
}
|
||||
|
||||
public void setReturn_url(String return_url) {
|
||||
this.return_url = return_url;
|
||||
}
|
||||
|
||||
public String getUrl() {
|
||||
return url;
|
||||
}
|
||||
|
||||
public void setUrl(String url) {
|
||||
this.url = url;
|
||||
}
|
||||
|
||||
public Short getIsSandbox() {
|
||||
return isSandbox;
|
||||
}
|
||||
|
||||
public void setIsSandbox(Short isSandbox) {
|
||||
this.isSandbox = isSandbox;
|
||||
}
|
||||
|
||||
public String getAlipay_public_key() {
|
||||
return alipay_public_key;
|
||||
}
|
||||
|
||||
public void setAlipay_public_key(String alipay_public_key) {
|
||||
this.alipay_public_key = alipay_public_key;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
package org.xxpay.dubbo.service.channel.wechat;
|
||||
|
||||
import org.springframework.boot.context.properties.ConfigurationProperties;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
/**
|
||||
* User: rizenguo
|
||||
* Date: 2014/10/29
|
||||
* Time: 14:40
|
||||
* 这里放置各种配置数据
|
||||
*/
|
||||
@Component
|
||||
@ConfigurationProperties(prefix="config.wx")
|
||||
public class WxPayProperties {
|
||||
|
||||
private String certRootPath;
|
||||
|
||||
private String notifyUrl;
|
||||
|
||||
public String getCertRootPath() {
|
||||
return certRootPath;
|
||||
}
|
||||
|
||||
public void setCertRootPath(String certRootPath) {
|
||||
this.certRootPath = certRootPath;
|
||||
}
|
||||
|
||||
public String getNotifyUrl() {
|
||||
return notifyUrl;
|
||||
}
|
||||
|
||||
public void setNotifyUrl(String notifyUrl) {
|
||||
this.notifyUrl = notifyUrl;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
package org.xxpay.dubbo.service.channel.wechat;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.binarywang.wxpay.config.WxPayConfig;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/8/25
|
||||
* @description:
|
||||
*/
|
||||
public class WxPayUtil {
|
||||
|
||||
/**
|
||||
* 获取微信支付配置
|
||||
* @param configParam
|
||||
* @param tradeType
|
||||
* @param certRootPath
|
||||
* @param notifyUrl
|
||||
* @return
|
||||
*/
|
||||
public static WxPayConfig getWxPayConfig(String configParam, String tradeType, String certRootPath, String notifyUrl) {
|
||||
WxPayConfig wxPayConfig = new WxPayConfig();
|
||||
JSONObject paramObj = JSON.parseObject(configParam);
|
||||
wxPayConfig.setMchId(paramObj.getString("mchId"));
|
||||
wxPayConfig.setAppId(paramObj.getString("appId"));
|
||||
wxPayConfig.setKeyPath(certRootPath + File.separator + paramObj.getString("certLocalPath"));
|
||||
wxPayConfig.setMchKey(paramObj.getString("key"));
|
||||
wxPayConfig.setNotifyUrl(notifyUrl);
|
||||
wxPayConfig.setTradeType(tradeType);
|
||||
return wxPayConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取微信支付配置
|
||||
* @param configParam
|
||||
* @return
|
||||
*/
|
||||
public static WxPayConfig getWxPayConfig(String configParam) {
|
||||
WxPayConfig wxPayConfig = new WxPayConfig();
|
||||
JSONObject paramObj = JSON.parseObject(configParam);
|
||||
wxPayConfig.setMchId(paramObj.getString("mchId"));
|
||||
wxPayConfig.setAppId(paramObj.getString("appId"));
|
||||
wxPayConfig.setMchKey(paramObj.getString("key"));
|
||||
return wxPayConfig;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,44 @@
|
|||
package org.xxpay.dubbo.service.impl;
|
||||
|
||||
import com.alibaba.dubbo.config.annotation.Service;
|
||||
import org.xxpay.common.domain.BaseParam;
|
||||
import org.xxpay.common.enumm.RetEnum;
|
||||
import org.xxpay.common.util.JsonUtil;
|
||||
import org.xxpay.common.util.MyLog;
|
||||
import org.xxpay.common.util.ObjectValidUtil;
|
||||
import org.xxpay.common.util.RpcUtil;
|
||||
import org.xxpay.dal.dao.model.MchInfo;
|
||||
import org.xxpay.dubbo.api.service.IMchInfoService;
|
||||
import org.xxpay.dubbo.service.BaseService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/8
|
||||
* @description:
|
||||
*/
|
||||
@Service(version = "1.0.0")
|
||||
public class MchInfoServiceImpl extends BaseService implements IMchInfoService {
|
||||
|
||||
private static final MyLog _log = MyLog.getLog(MchInfoServiceImpl.class);
|
||||
|
||||
@Override
|
||||
public Map selectMchInfo(String jsonParam) {
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("查询商户信息失败, {}. jsonParam={}", RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
String mchId = baseParam.isNullValue("mchId") ? null : bizParamMap.get("mchId").toString();
|
||||
if (ObjectValidUtil.isInvalid(mchId)) {
|
||||
_log.warn("查询商户信息失败, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
MchInfo mchInfo = super.baseSelectMchInfo(mchId);
|
||||
if(mchInfo == null) return RpcUtil.createFailResult(baseParam, RetEnum.RET_BIZ_DATA_NOT_EXISTS);
|
||||
String jsonResult = JsonUtil.object2Json(mchInfo);
|
||||
return RpcUtil.createBizResult(baseParam, jsonResult);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,292 @@
|
|||
package org.xxpay.dubbo.service.impl;
|
||||
|
||||
import com.alibaba.dubbo.config.annotation.Service;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.internal.util.AlipaySignature;
|
||||
import com.github.binarywang.wxpay.bean.notify.WxPayNotifyResponse;
|
||||
import com.github.binarywang.wxpay.bean.notify.WxPayOrderNotifyResult;
|
||||
import com.github.binarywang.wxpay.config.WxPayConfig;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.xxpay.common.constant.PayConstant;
|
||||
import org.xxpay.common.domain.BaseParam;
|
||||
import org.xxpay.common.enumm.RetEnum;
|
||||
import org.xxpay.common.util.*;
|
||||
import org.xxpay.dal.dao.model.PayChannel;
|
||||
import org.xxpay.dal.dao.model.PayOrder;
|
||||
import org.xxpay.dubbo.api.service.INotifyPayService;
|
||||
import org.xxpay.dubbo.service.Notify4BasePay;
|
||||
import org.xxpay.dubbo.service.channel.alipay.AlipayConfig;
|
||||
import org.xxpay.dubbo.service.channel.wechat.WxPayUtil;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/10
|
||||
* @description:
|
||||
*/
|
||||
@Service(version = "1.0.0")
|
||||
public class NotifyPayServiceImpl extends Notify4BasePay implements INotifyPayService {
|
||||
|
||||
private static final MyLog _log = MyLog.getLog(NotifyPayServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private AlipayConfig alipayConfig;
|
||||
|
||||
@Override
|
||||
public Map doAliPayNotify(String jsonParam) {
|
||||
String logPrefix = "【处理支付宝支付回调】";
|
||||
_log.info("====== 开始处理支付宝支付回调通知 ======");
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("处理支付宝支付回调失败, {}. jsonParam={}", RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
Map params = baseParam.isNullValue("params") ? null : (Map) bizParamMap.get("params");
|
||||
if (ObjectValidUtil.isInvalid(params)) {
|
||||
_log.warn("处理支付宝支付回调失败, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
Map<String, Object> payContext = new HashMap();
|
||||
PayOrder payOrder;
|
||||
payContext.put("parameters", params);
|
||||
if(!verifyAliPayParams(payContext)) {
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_BIZ_PAY_NOTIFY_VERIFY_FAIL);
|
||||
}
|
||||
_log.info("{}验证支付通知数据及签名通过", logPrefix);
|
||||
String trade_status = params.get("trade_status").toString(); // 交易状态
|
||||
// 支付状态成功或者完成
|
||||
if (trade_status.equals(PayConstant.AlipayConstant.TRADE_STATUS_SUCCESS) ||
|
||||
trade_status.equals(PayConstant.AlipayConstant.TRADE_STATUS_FINISHED)) {
|
||||
int updatePayOrderRows;
|
||||
payOrder = (PayOrder)payContext.get("payOrder");
|
||||
byte payStatus = payOrder.getStatus(); // 0:订单生成,1:支付中,-1:支付失败,2:支付成功,3:业务处理完成,-2:订单过期
|
||||
if (payStatus != PayConstant.PAY_STATUS_SUCCESS && payStatus != PayConstant.PAY_STATUS_COMPLETE) {
|
||||
updatePayOrderRows = super.baseUpdateStatus4Success(payOrder.getPayOrderId());
|
||||
if (updatePayOrderRows != 1) {
|
||||
_log.error("{}更新支付状态失败,将payOrderId={},更新payStatus={}失败", logPrefix, payOrder.getPayOrderId(), PayConstant.PAY_STATUS_SUCCESS);
|
||||
_log.info("{}响应给支付宝结果:{}", logPrefix, PayConstant.RETURN_ALIPAY_VALUE_FAIL);
|
||||
return RpcUtil.createBizResult(baseParam, PayConstant.RETURN_ALIPAY_VALUE_FAIL);
|
||||
}
|
||||
_log.info("{}更新支付状态成功,将payOrderId={},更新payStatus={}成功", logPrefix, payOrder.getPayOrderId(), PayConstant.PAY_STATUS_SUCCESS);
|
||||
payOrder.setStatus(PayConstant.PAY_STATUS_SUCCESS);
|
||||
}
|
||||
}else{
|
||||
// 其他状态
|
||||
_log.info("{}支付状态trade_status={},不做业务处理", logPrefix, trade_status);
|
||||
_log.info("{}响应给支付宝结果:{}", logPrefix, PayConstant.RETURN_ALIPAY_VALUE_SUCCESS);
|
||||
return RpcUtil.createBizResult(baseParam, PayConstant.RETURN_ALIPAY_VALUE_SUCCESS);
|
||||
}
|
||||
doNotify(payOrder);
|
||||
_log.info("====== 完成处理支付宝支付回调通知 ======");
|
||||
return RpcUtil.createBizResult(baseParam, PayConstant.RETURN_ALIPAY_VALUE_SUCCESS);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map doWxPayNotify(String jsonParam) {
|
||||
String logPrefix = "【处理微信支付回调】";
|
||||
_log.info("====== 开始处理微信支付回调通知 ======");
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
try {
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("处理微信支付回调失败, {}. jsonParam={}", RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createBizResult(baseParam, WxPayNotifyResponse.fail(RetEnum.RET_PARAM_NOT_FOUND.getMessage()));
|
||||
//return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
String xmlResult = baseParam.isNullValue("xmlResult") ? null : bizParamMap.get("xmlResult").toString();
|
||||
if (ObjectValidUtil.isInvalid(xmlResult)) {
|
||||
_log.warn("处理微信支付回调失败, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createBizResult(baseParam, WxPayNotifyResponse.fail(RetEnum.RET_PARAM_INVALID.getMessage()));
|
||||
//return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
WxPayService wxPayService = new WxPayServiceImpl();
|
||||
WxPayOrderNotifyResult result = WxPayOrderNotifyResult.fromXML(xmlResult);
|
||||
Map<String, Object> payContext = new HashMap();
|
||||
payContext.put("parameters", result);
|
||||
// 验证业务数据是否正确,验证通过后返回PayOrder和WxPayConfig对象
|
||||
if(!verifyWxPayParams(payContext)) {
|
||||
return RpcUtil.createBizResult(baseParam, WxPayNotifyResponse.fail((String) payContext.get("retMsg")));
|
||||
}
|
||||
PayOrder payOrder = (PayOrder) payContext.get("payOrder");
|
||||
WxPayConfig wxPayConfig = (WxPayConfig) payContext.get("wxPayConfig");
|
||||
wxPayService.setConfig(wxPayConfig);
|
||||
// 这里做了签名校验(这里又做了一次xml转换对象,可以考虑优化)
|
||||
wxPayService.parseOrderNotifyResult(xmlResult);
|
||||
// 处理订单
|
||||
byte payStatus = payOrder.getStatus(); // 0:订单生成,1:支付中,-1:支付失败,2:支付成功,3:业务处理完成,-2:订单过期
|
||||
if (payStatus != PayConstant.PAY_STATUS_SUCCESS && payStatus != PayConstant.PAY_STATUS_COMPLETE) {
|
||||
int updatePayOrderRows = super.baseUpdateStatus4Success(payOrder.getPayOrderId());
|
||||
if (updatePayOrderRows != 1) {
|
||||
_log.error("{}更新支付状态失败,将payOrderId={},更新payStatus={}失败", logPrefix, payOrder.getPayOrderId(), PayConstant.PAY_STATUS_SUCCESS);
|
||||
return RpcUtil.createBizResult(baseParam, WxPayNotifyResponse.fail("处理订单失败"));
|
||||
}
|
||||
_log.error("{}更新支付状态成功,将payOrderId={},更新payStatus={}成功", logPrefix, payOrder.getPayOrderId(), PayConstant.PAY_STATUS_SUCCESS);
|
||||
payOrder.setStatus(PayConstant.PAY_STATUS_SUCCESS);
|
||||
}
|
||||
// 业务系统后端通知
|
||||
doNotify(payOrder);
|
||||
_log.info("====== 完成处理微信支付回调通知 ======");
|
||||
return RpcUtil.createBizResult(baseParam, WxPayNotifyResponse.success("OK"));
|
||||
} catch (WxPayException e) {
|
||||
//出现业务错误
|
||||
_log.error(e, "微信回调结果异常,异常原因");
|
||||
_log.info("{}请求数据result_code=FAIL", logPrefix);
|
||||
_log.info("err_code:", e.getErrCode());
|
||||
_log.info("err_code_des:", e.getErrCodeDes());
|
||||
return RpcUtil.createBizResult(baseParam, WxPayNotifyResponse.fail(e.getMessage()));
|
||||
} catch (Exception e) {
|
||||
_log.error(e, "微信回调结果异常,异常原因");
|
||||
return RpcUtil.createBizResult(baseParam, WxPayNotifyResponse.fail(e.getMessage()));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map sendBizPayNotify(String jsonParam) {
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("发送业务支付通知失败, {}. jsonParam={}", RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
String payOrderId = baseParam.isNullValue("payOrderId") ? null : bizParamMap.get("payOrderId").toString();
|
||||
if(ObjectValidUtil.isInvalid(payOrderId)) {
|
||||
_log.warn("发送业务支付通知失败, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
PayOrder payOrder = super.baseSelectPayOrder(payOrderId);
|
||||
if(payOrder == null) return RpcUtil.createFailResult(baseParam, RetEnum.RET_BIZ_DATA_NOT_EXISTS);
|
||||
try {
|
||||
// 发送业务支付通知
|
||||
super.doNotify(payOrder);
|
||||
}catch (Exception e) {
|
||||
return RpcUtil.createBizResult(baseParam, 0);
|
||||
}
|
||||
return RpcUtil.createBizResult(baseParam, 1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 验证支付宝支付通知参数
|
||||
* @return
|
||||
*/
|
||||
public boolean verifyAliPayParams(Map<String, Object> payContext) {
|
||||
Map<String,String> params = (Map<String,String>)payContext.get("parameters");
|
||||
String out_trade_no = params.get("out_trade_no"); // 商户订单号
|
||||
String total_amount = params.get("total_amount"); // 支付金额
|
||||
if (StringUtils.isEmpty(out_trade_no)) {
|
||||
_log.error("AliPay Notify parameter out_trade_no is empty. out_trade_no={}", out_trade_no);
|
||||
payContext.put("retMsg", "out_trade_no is empty");
|
||||
return false;
|
||||
}
|
||||
if (StringUtils.isEmpty(total_amount)) {
|
||||
_log.error("AliPay Notify parameter total_amount is empty. total_fee={}", total_amount);
|
||||
payContext.put("retMsg", "total_amount is empty");
|
||||
return false;
|
||||
}
|
||||
String errorMessage;
|
||||
// 查询payOrder记录
|
||||
String payOrderId = out_trade_no;
|
||||
PayOrder payOrder = super.baseSelectPayOrder(payOrderId);
|
||||
if (payOrder == null) {
|
||||
_log.error("Can't found payOrder form db. payOrderId={}, ", payOrderId);
|
||||
payContext.put("retMsg", "Can't found payOrder");
|
||||
return false;
|
||||
}
|
||||
// 查询payChannel记录
|
||||
String mchId = payOrder.getMchId();
|
||||
String channelId = payOrder.getChannelId();
|
||||
PayChannel payChannel = super.baseSelectPayChannel(mchId, channelId);
|
||||
if(payChannel == null) {
|
||||
_log.error("Can't found payChannel form db. mchId={} channelId={}, ", payOrderId, mchId, channelId);
|
||||
payContext.put("retMsg", "Can't found payChannel");
|
||||
return false;
|
||||
}
|
||||
boolean verify_result = false;
|
||||
try {
|
||||
verify_result = AlipaySignature.rsaCheckV1(params, alipayConfig.init(payChannel.getParam()).getAlipay_public_key(), AlipayConfig.CHARSET, "RSA2");
|
||||
} catch (AlipayApiException e) {
|
||||
_log.error(e, "AlipaySignature.rsaCheckV1 error");
|
||||
}
|
||||
|
||||
// 验证签名
|
||||
if (!verify_result) {
|
||||
errorMessage = "rsaCheckV1 failed.";
|
||||
_log.error("AliPay Notify parameter {}", errorMessage);
|
||||
payContext.put("retMsg", errorMessage);
|
||||
return false;
|
||||
}
|
||||
|
||||
// 核对金额
|
||||
long aliPayAmt = new BigDecimal(total_amount).movePointRight(2).longValue();
|
||||
long dbPayAmt = payOrder.getAmount().longValue();
|
||||
if (dbPayAmt != aliPayAmt) {
|
||||
_log.error("db payOrder record payPrice not equals total_amount. total_amount={},payOrderId={}", total_amount, payOrderId);
|
||||
payContext.put("retMsg", "");
|
||||
return false;
|
||||
}
|
||||
payContext.put("payOrder", payOrder);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证微信支付通知参数
|
||||
* @return
|
||||
*/
|
||||
public boolean verifyWxPayParams(Map<String, Object> payContext) {
|
||||
WxPayOrderNotifyResult params = (WxPayOrderNotifyResult)payContext.get("parameters");
|
||||
|
||||
//校验结果是否成功
|
||||
if (!PayConstant.RETURN_VALUE_SUCCESS.equalsIgnoreCase(params.getResultCode())
|
||||
|| !PayConstant.RETURN_VALUE_SUCCESS.equalsIgnoreCase(params.getResultCode())) {
|
||||
_log.error("returnCode={},resultCode={},errCode={},errCodeDes={}", params.getReturnCode(), params.getResultCode(), params.getErrCode(), params.getErrCodeDes());
|
||||
payContext.put("retMsg", "notify data failed");
|
||||
return false;
|
||||
}
|
||||
|
||||
Integer total_fee = params.getTotalFee(); // 总金额
|
||||
String out_trade_no = params.getOutTradeNo(); // 商户系统订单号
|
||||
|
||||
// 查询payOrder记录
|
||||
String payOrderId = out_trade_no;
|
||||
PayOrder payOrder = super.baseSelectPayOrder(payOrderId);
|
||||
if (payOrder==null) {
|
||||
_log.error("Can't found payOrder form db. payOrderId={}, ", payOrderId);
|
||||
payContext.put("retMsg", "Can't found payOrder");
|
||||
return false;
|
||||
}
|
||||
|
||||
// 查询payChannel记录
|
||||
String mchId = payOrder.getMchId();
|
||||
String channelId = payOrder.getChannelId();
|
||||
PayChannel payChannel = super.baseSelectPayChannel(mchId, channelId);
|
||||
if(payChannel == null) {
|
||||
_log.error("Can't found payChannel form db. mchId={} channelId={}, ", payOrderId, mchId, channelId);
|
||||
payContext.put("retMsg", "Can't found payChannel");
|
||||
return false;
|
||||
}
|
||||
payContext.put("wxPayConfig", WxPayUtil.getWxPayConfig(payChannel.getParam()));
|
||||
|
||||
// 核对金额
|
||||
long wxPayAmt = new BigDecimal(total_fee).longValue();
|
||||
long dbPayAmt = payOrder.getAmount().longValue();
|
||||
if (dbPayAmt != wxPayAmt) {
|
||||
_log.error("db payOrder record payPrice not equals total_fee. total_fee={},payOrderId={}", total_fee, payOrderId);
|
||||
payContext.put("retMsg", "total_fee is not the same");
|
||||
return false;
|
||||
}
|
||||
|
||||
payContext.put("payOrder", payOrder);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,287 @@
|
|||
package org.xxpay.dubbo.service.impl;
|
||||
|
||||
import com.alibaba.dubbo.config.annotation.Service;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alipay.api.AlipayApiException;
|
||||
import com.alipay.api.AlipayClient;
|
||||
import com.alipay.api.DefaultAlipayClient;
|
||||
import com.alipay.api.domain.AlipayTradeAppPayModel;
|
||||
import com.alipay.api.domain.AlipayTradePagePayModel;
|
||||
import com.alipay.api.domain.AlipayTradePrecreateModel;
|
||||
import com.alipay.api.domain.AlipayTradeWapPayModel;
|
||||
import com.alipay.api.request.AlipayTradeAppPayRequest;
|
||||
import com.alipay.api.request.AlipayTradePagePayRequest;
|
||||
import com.alipay.api.request.AlipayTradePrecreateRequest;
|
||||
import com.alipay.api.request.AlipayTradeWapPayRequest;
|
||||
import org.apache.commons.lang3.ObjectUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.xxpay.common.constant.PayConstant;
|
||||
import org.xxpay.common.domain.BaseParam;
|
||||
import org.xxpay.common.enumm.RetEnum;
|
||||
import org.xxpay.common.util.*;
|
||||
import org.xxpay.dal.dao.model.PayChannel;
|
||||
import org.xxpay.dal.dao.model.PayOrder;
|
||||
import org.xxpay.dubbo.api.service.IPayChannel4AliService;
|
||||
import org.xxpay.dubbo.service.BaseService;
|
||||
import org.xxpay.dubbo.service.channel.alipay.AlipayConfig;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/10
|
||||
* @description:
|
||||
*/
|
||||
@Service(version = "1.0.0")
|
||||
public class PayChannel4AliServiceImpl extends BaseService implements IPayChannel4AliService {
|
||||
|
||||
private static final MyLog _log = MyLog.getLog(PayChannel4AliServiceImpl.class);
|
||||
|
||||
@Autowired
|
||||
private AlipayConfig alipayConfig;
|
||||
|
||||
@Override
|
||||
public Map doAliPayWapReq(String jsonParam) {
|
||||
String logPrefix = "【支付宝WAP支付下单】";
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("{}失败, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
JSONObject payOrderObj = baseParam.isNullValue("payOrder") ? null : JSONObject.parseObject(bizParamMap.get("payOrder").toString());
|
||||
PayOrder payOrder = BeanConvertUtils.map2Bean(payOrderObj, PayOrder.class);
|
||||
if (ObjectValidUtil.isInvalid(payOrder)) {
|
||||
_log.warn("{}失败, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
String payOrderId = payOrder.getPayOrderId();
|
||||
String mchId = payOrder.getMchId();
|
||||
String channelId = payOrder.getChannelId();
|
||||
PayChannel payChannel = super.baseSelectPayChannel(mchId, channelId);
|
||||
alipayConfig.init(payChannel.getParam());
|
||||
AlipayClient client = new DefaultAlipayClient(alipayConfig.getUrl(), alipayConfig.getApp_id(), alipayConfig.getRsa_private_key(), AlipayConfig.FORMAT, AlipayConfig.CHARSET, alipayConfig.getAlipay_public_key(), AlipayConfig.SIGNTYPE);
|
||||
AlipayTradeWapPayRequest alipay_request = new AlipayTradeWapPayRequest();
|
||||
// 封装请求支付信息
|
||||
AlipayTradeWapPayModel model=new AlipayTradeWapPayModel();
|
||||
model.setOutTradeNo(payOrderId);
|
||||
model.setSubject(payOrder.getSubject());
|
||||
model.setTotalAmount(AmountUtil.convertCent2Dollar(payOrder.getAmount().toString()));
|
||||
model.setBody(payOrder.getBody());
|
||||
model.setProductCode("QUICK_WAP_PAY");
|
||||
// 获取objParams参数
|
||||
String objParams = payOrder.getExtra();
|
||||
if (StringUtils.isNotEmpty(objParams)) {
|
||||
try {
|
||||
JSONObject objParamsJson = JSON.parseObject(objParams);
|
||||
if(StringUtils.isNotBlank(objParamsJson.getString("quit_url"))) {
|
||||
model.setQuitUrl(objParamsJson.getString("quit_url"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
_log.error("{}objParams参数格式错误!", logPrefix);
|
||||
}
|
||||
}
|
||||
alipay_request.setBizModel(model);
|
||||
// 设置异步通知地址
|
||||
alipay_request.setNotifyUrl(alipayConfig.getNotify_url());
|
||||
// 设置同步地址
|
||||
alipay_request.setReturnUrl(alipayConfig.getReturn_url());
|
||||
String payUrl = null;
|
||||
try {
|
||||
payUrl = client.pageExecute(alipay_request).getBody();
|
||||
} catch (AlipayApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
_log.info("{}生成跳转路径:payUrl={}", logPrefix, payUrl);
|
||||
super.baseUpdateStatus4Ing(payOrderId, null);
|
||||
_log.info("{}生成请求支付宝数据,req={}", logPrefix, alipay_request.getBizModel());
|
||||
_log.info("###### 商户统一下单处理完成 ######");
|
||||
Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
|
||||
map.put("payOrderId", payOrderId);
|
||||
map.put("payUrl", payUrl);
|
||||
return RpcUtil.createBizResult(baseParam, map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map doAliPayPcReq(String jsonParam) {
|
||||
String logPrefix = "【支付宝PC支付下单】";
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("{}失败, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
JSONObject payOrderObj = baseParam.isNullValue("payOrder") ? null : JSONObject.parseObject(bizParamMap.get("payOrder").toString());
|
||||
PayOrder payOrder = BeanConvertUtils.map2Bean(payOrderObj, PayOrder.class);
|
||||
if (ObjectValidUtil.isInvalid(payOrder)) {
|
||||
_log.warn("{}失败, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
String payOrderId = payOrder.getPayOrderId();
|
||||
String mchId = payOrder.getMchId();
|
||||
String channelId = payOrder.getChannelId();
|
||||
PayChannel payChannel = super.baseSelectPayChannel(mchId, channelId);
|
||||
alipayConfig.init(payChannel.getParam());
|
||||
AlipayClient client = new DefaultAlipayClient(alipayConfig.getUrl(), alipayConfig.getApp_id(), alipayConfig.getRsa_private_key(), AlipayConfig.FORMAT, AlipayConfig.CHARSET, alipayConfig.getAlipay_public_key(), AlipayConfig.SIGNTYPE);
|
||||
AlipayTradePagePayRequest alipay_request = new AlipayTradePagePayRequest();
|
||||
// 封装请求支付信息
|
||||
AlipayTradePagePayModel model=new AlipayTradePagePayModel();
|
||||
model.setOutTradeNo(payOrderId);
|
||||
model.setSubject(payOrder.getSubject());
|
||||
model.setTotalAmount(AmountUtil.convertCent2Dollar(payOrder.getAmount().toString()));
|
||||
model.setBody(payOrder.getBody());
|
||||
model.setProductCode("FAST_INSTANT_TRADE_PAY");
|
||||
// 获取objParams参数
|
||||
String objParams = payOrder.getExtra();
|
||||
String qr_pay_mode = "2";
|
||||
String qrcode_width = "200";
|
||||
if (StringUtils.isNotEmpty(objParams)) {
|
||||
try {
|
||||
JSONObject objParamsJson = JSON.parseObject(objParams);
|
||||
qr_pay_mode = ObjectUtils.toString(objParamsJson.getString("qr_pay_mode"), "2");
|
||||
qrcode_width = ObjectUtils.toString(objParamsJson.getString("qrcode_width"), "200");
|
||||
} catch (Exception e) {
|
||||
_log.error("{}objParams参数格式错误!", logPrefix);
|
||||
}
|
||||
}
|
||||
model.setQrPayMode(qr_pay_mode);
|
||||
model.setQrcodeWidth(Long.parseLong(qrcode_width));
|
||||
alipay_request.setBizModel(model);
|
||||
// 设置异步通知地址
|
||||
alipay_request.setNotifyUrl(alipayConfig.getNotify_url());
|
||||
// 设置同步地址
|
||||
alipay_request.setReturnUrl(alipayConfig.getReturn_url());
|
||||
String payUrl = null;
|
||||
try {
|
||||
payUrl = client.pageExecute(alipay_request).getBody();
|
||||
} catch (AlipayApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
_log.info("{}生成跳转路径:payUrl={}", logPrefix, payUrl);
|
||||
super.baseUpdateStatus4Ing(payOrderId, null);
|
||||
_log.info("{}生成请求支付宝数据,req={}", logPrefix, alipay_request.getBizModel());
|
||||
_log.info("###### 商户统一下单处理完成 ######");
|
||||
Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
|
||||
map.put("payOrderId", payOrderId);
|
||||
map.put("payUrl", payUrl);
|
||||
return RpcUtil.createBizResult(baseParam, map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map doAliPayMobileReq(String jsonParam) {
|
||||
String logPrefix = "【支付宝APP支付下单】";
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("{}失败, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
JSONObject payOrderObj = baseParam.isNullValue("payOrder") ? null : JSONObject.parseObject(bizParamMap.get("payOrder").toString());
|
||||
PayOrder payOrder = BeanConvertUtils.map2Bean(payOrderObj, PayOrder.class);
|
||||
if (ObjectValidUtil.isInvalid(payOrder)) {
|
||||
_log.warn("{}失败, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
String payOrderId = payOrder.getPayOrderId();
|
||||
String mchId = payOrder.getMchId();
|
||||
String channelId = payOrder.getChannelId();
|
||||
PayChannel payChannel = super.baseSelectPayChannel(mchId, channelId);
|
||||
alipayConfig.init(payChannel.getParam());
|
||||
AlipayClient client = new DefaultAlipayClient(alipayConfig.getUrl(), alipayConfig.getApp_id(), alipayConfig.getRsa_private_key(), AlipayConfig.FORMAT, AlipayConfig.CHARSET, alipayConfig.getAlipay_public_key(), AlipayConfig.SIGNTYPE);
|
||||
AlipayTradeAppPayRequest alipay_request = new AlipayTradeAppPayRequest();
|
||||
// 封装请求支付信息
|
||||
AlipayTradeAppPayModel model=new AlipayTradeAppPayModel();
|
||||
model.setOutTradeNo(payOrderId);
|
||||
model.setSubject(payOrder.getSubject());
|
||||
model.setTotalAmount(AmountUtil.convertCent2Dollar(payOrder.getAmount().toString()));
|
||||
model.setBody(payOrder.getBody());
|
||||
model.setProductCode("QUICK_MSECURITY_PAY");
|
||||
alipay_request.setBizModel(model);
|
||||
// 设置异步通知地址
|
||||
alipay_request.setNotifyUrl(alipayConfig.getNotify_url());
|
||||
// 设置同步地址
|
||||
alipay_request.setReturnUrl(alipayConfig.getReturn_url());
|
||||
String payParams = null;
|
||||
try {
|
||||
payParams = client.sdkExecute(alipay_request).getBody();
|
||||
} catch (AlipayApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
super.baseUpdateStatus4Ing(payOrderId, null);
|
||||
_log.info("{}生成请求支付宝数据,payParams={}", logPrefix, payParams);
|
||||
_log.info("###### 商户统一下单处理完成 ######");
|
||||
Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
|
||||
map.put("payOrderId", payOrderId);
|
||||
map.put("payParams", payParams);
|
||||
return RpcUtil.createBizResult(baseParam, map);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map doAliPayQrReq(String jsonParam) {
|
||||
String logPrefix = "【支付宝当面付之扫码支付下单】";
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("{}失败, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
JSONObject payOrderObj = baseParam.isNullValue("payOrder") ? null : JSONObject.parseObject(bizParamMap.get("payOrder").toString());
|
||||
PayOrder payOrder = BeanConvertUtils.map2Bean(payOrderObj, PayOrder.class);
|
||||
if (ObjectValidUtil.isInvalid(payOrder)) {
|
||||
_log.warn("{}失败, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
String payOrderId = payOrder.getPayOrderId();
|
||||
String mchId = payOrder.getMchId();
|
||||
String channelId = payOrder.getChannelId();
|
||||
PayChannel payChannel = super.baseSelectPayChannel(mchId, channelId);
|
||||
alipayConfig.init(payChannel.getParam());
|
||||
AlipayClient client = new DefaultAlipayClient(alipayConfig.getUrl(), alipayConfig.getApp_id(), alipayConfig.getRsa_private_key(), AlipayConfig.FORMAT, AlipayConfig.CHARSET, alipayConfig.getAlipay_public_key(), AlipayConfig.SIGNTYPE);
|
||||
AlipayTradePrecreateRequest alipay_request = new AlipayTradePrecreateRequest();
|
||||
// 封装请求支付信息
|
||||
AlipayTradePrecreateModel model=new AlipayTradePrecreateModel();
|
||||
model.setOutTradeNo(payOrderId);
|
||||
model.setSubject(payOrder.getSubject());
|
||||
model.setTotalAmount(AmountUtil.convertCent2Dollar(payOrder.getAmount().toString()));
|
||||
model.setBody(payOrder.getBody());
|
||||
// 获取objParams参数
|
||||
String objParams = payOrder.getExtra();
|
||||
if (StringUtils.isNotEmpty(objParams)) {
|
||||
try {
|
||||
JSONObject objParamsJson = JSON.parseObject(objParams);
|
||||
if(StringUtils.isNotBlank(objParamsJson.getString("discountable_amount"))) {
|
||||
//可打折金额
|
||||
model.setDiscountableAmount(objParamsJson.getString("discountable_amount"));
|
||||
}
|
||||
if(StringUtils.isNotBlank(objParamsJson.getString("undiscountable_amount"))) {
|
||||
//不可打折金额
|
||||
model.setUndiscountableAmount(objParamsJson.getString("undiscountable_amount"));
|
||||
}
|
||||
} catch (Exception e) {
|
||||
_log.error("{}objParams参数格式错误!", logPrefix);
|
||||
}
|
||||
}
|
||||
alipay_request.setBizModel(model);
|
||||
// 设置异步通知地址
|
||||
alipay_request.setNotifyUrl(alipayConfig.getNotify_url());
|
||||
// 设置同步地址
|
||||
alipay_request.setReturnUrl(alipayConfig.getReturn_url());
|
||||
String payUrl = null;
|
||||
try {
|
||||
payUrl = client.execute(alipay_request).getBody();
|
||||
} catch (AlipayApiException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
_log.info("{}生成跳转路径:payUrl={}", logPrefix, payUrl);
|
||||
super.baseUpdateStatus4Ing(payOrderId, null);
|
||||
_log.info("{}生成请求支付宝数据,req={}", logPrefix, alipay_request.getBizModel());
|
||||
_log.info("###### 商户统一下单处理完成 ######");
|
||||
Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
|
||||
map.put("payOrderId", payOrderId);
|
||||
map.put("payUrl", payUrl);
|
||||
return RpcUtil.createBizResult(baseParam, map);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,198 @@
|
|||
package org.xxpay.dubbo.service.impl;
|
||||
|
||||
import com.alibaba.dubbo.config.annotation.Service;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
||||
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult;
|
||||
import com.github.binarywang.wxpay.config.WxPayConfig;
|
||||
import com.github.binarywang.wxpay.constant.WxPayConstants;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
||||
import com.github.binarywang.wxpay.util.SignUtils;
|
||||
import org.xxpay.common.constant.PayConstant;
|
||||
import org.xxpay.common.domain.BaseParam;
|
||||
import org.xxpay.common.enumm.RetEnum;
|
||||
import org.xxpay.common.util.*;
|
||||
import org.xxpay.dal.dao.model.PayChannel;
|
||||
import org.xxpay.dal.dao.model.PayOrder;
|
||||
import org.xxpay.dubbo.api.service.IPayChannel4WxService;
|
||||
import org.xxpay.dubbo.service.BaseService;
|
||||
import org.xxpay.dubbo.service.channel.wechat.WxPayProperties;
|
||||
import org.xxpay.dubbo.service.channel.wechat.WxPayUtil;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 支付渠道接口:微信
|
||||
* @author dingzhiwei jmdhappy@126.com
|
||||
* @date 2017-09-05
|
||||
* @version V1.0
|
||||
* @Copyright: www.xxpay.org
|
||||
*/
|
||||
@Service(version = "1.0.0")
|
||||
public class PayChannel4WxServiceImpl extends BaseService implements IPayChannel4WxService {
|
||||
|
||||
private final MyLog _log = MyLog.getLog(PayChannel4WxServiceImpl.class);
|
||||
|
||||
@Resource
|
||||
private WxPayProperties wxPayProperties;
|
||||
|
||||
public Map doWxPayReq(String jsonParam) {
|
||||
String logPrefix = "【微信支付统一下单】";
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
try{
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("{}失败, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
JSONObject payOrderObj = baseParam.isNullValue("payOrder") ? null : JSONObject.parseObject(bizParamMap.get("payOrder").toString());
|
||||
String tradeType = baseParam.isNullValue("tradeType") ? null : bizParamMap.get("tradeType").toString();
|
||||
PayOrder payOrder = BeanConvertUtils.map2Bean(payOrderObj, PayOrder.class);
|
||||
if (ObjectValidUtil.isInvalid(payOrder, tradeType)) {
|
||||
_log.warn("{}失败, {}. jsonParam={}", logPrefix, RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
String mchId = payOrder.getMchId();
|
||||
String channelId = payOrder.getChannelId();
|
||||
PayChannel payChannel = super.baseSelectPayChannel(mchId, channelId);
|
||||
WxPayConfig wxPayConfig = WxPayUtil.getWxPayConfig(payChannel.getParam(), tradeType, wxPayProperties.getCertRootPath(), wxPayProperties.getNotifyUrl());
|
||||
WxPayService wxPayService = new WxPayServiceImpl();
|
||||
wxPayService.setConfig(wxPayConfig);
|
||||
WxPayUnifiedOrderRequest wxPayUnifiedOrderRequest = buildUnifiedOrderRequest(payOrder, wxPayConfig);
|
||||
String payOrderId = payOrder.getPayOrderId();
|
||||
WxPayUnifiedOrderResult wxPayUnifiedOrderResult;
|
||||
try {
|
||||
wxPayUnifiedOrderResult = wxPayService.unifiedOrder(wxPayUnifiedOrderRequest);
|
||||
_log.info("{} >>> 下单成功", logPrefix);
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("payOrderId", payOrderId);
|
||||
map.put("prepayId", wxPayUnifiedOrderResult.getPrepayId());
|
||||
int result = super.baseUpdateStatus4Ing(payOrderId, wxPayUnifiedOrderResult.getPrepayId());
|
||||
_log.info("更新第三方支付订单号:payOrderId={},prepayId={},result={}", payOrderId, wxPayUnifiedOrderResult.getPrepayId(), result);
|
||||
switch (tradeType) {
|
||||
case PayConstant.WxConstant.TRADE_TYPE_NATIVE : {
|
||||
map.put("codeUrl", wxPayUnifiedOrderResult.getCodeURL()); // 二维码支付链接
|
||||
break;
|
||||
}
|
||||
case PayConstant.WxConstant.TRADE_TYPE_APP : {
|
||||
Map<String, String> payInfo = new HashMap<>();
|
||||
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
String nonceStr = String.valueOf(System.currentTimeMillis());
|
||||
// APP支付绑定的是微信开放平台上的账号,APPID为开放平台上绑定APP后发放的参数
|
||||
String appId = wxPayConfig.getAppId();
|
||||
Map<String, String> configMap = new HashMap<>();
|
||||
// 此map用于参与调起sdk支付的二次签名,格式全小写,timestamp只能是10位,格式固定,切勿修改
|
||||
String partnerId = wxPayConfig.getMchId();
|
||||
configMap.put("prepayid", wxPayUnifiedOrderResult.getPrepayId());
|
||||
configMap.put("partnerid", partnerId);
|
||||
String packageValue = "Sign=WXPay";
|
||||
configMap.put("package", packageValue);
|
||||
configMap.put("timestamp", timestamp);
|
||||
configMap.put("noncestr", nonceStr);
|
||||
configMap.put("appid", appId);
|
||||
// 此map用于客户端与微信服务器交互
|
||||
payInfo.put("sign", SignUtils.createSign(configMap, wxPayConfig.getMchKey(), null));
|
||||
payInfo.put("prepayId", wxPayUnifiedOrderResult.getPrepayId());
|
||||
payInfo.put("partnerId", partnerId);
|
||||
payInfo.put("appId", appId);
|
||||
payInfo.put("packageValue", packageValue);
|
||||
payInfo.put("timeStamp", timestamp);
|
||||
payInfo.put("nonceStr", nonceStr);
|
||||
map.put("payParams", payInfo);
|
||||
break;
|
||||
}
|
||||
case PayConstant.WxConstant.TRADE_TYPE_JSPAI : {
|
||||
Map<String, String> payInfo = new HashMap<>();
|
||||
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
String nonceStr = String.valueOf(System.currentTimeMillis());
|
||||
payInfo.put("appId", wxPayUnifiedOrderResult.getAppid());
|
||||
// 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
|
||||
payInfo.put("timeStamp", timestamp);
|
||||
payInfo.put("nonceStr", nonceStr);
|
||||
payInfo.put("package", "prepay_id=" + wxPayUnifiedOrderResult.getPrepayId());
|
||||
payInfo.put("signType", WxPayConstants.SignType.MD5);
|
||||
payInfo.put("paySign", SignUtils.createSign(payInfo, wxPayConfig.getMchKey(), null));
|
||||
map.put("payParams", payInfo);
|
||||
break;
|
||||
}
|
||||
case PayConstant.WxConstant.TRADE_TYPE_MWEB : {
|
||||
map.put("payUrl", wxPayUnifiedOrderResult.getMwebUrl()); // h5支付链接地址
|
||||
break;
|
||||
}
|
||||
}
|
||||
return RpcUtil.createBizResult(baseParam, map);
|
||||
} catch (WxPayException e) {
|
||||
_log.error(e, "下单失败");
|
||||
//出现业务错误
|
||||
_log.info("{}下单返回失败", logPrefix);
|
||||
_log.info("err_code:{}", e.getErrCode());
|
||||
_log.info("err_code_des:{}", e.getErrCodeDes());
|
||||
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_BIZ_WX_PAY_CREATE_FAIL);
|
||||
|
||||
// return XXPayUtil.makeRetData(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_FAIL, "0111", "调用微信支付失败," + e.getErrCode() + ":" + e.getErrCodeDes()), resKey);
|
||||
}
|
||||
}catch (Exception e) {
|
||||
_log.error(e, "微信支付统一下单异常");
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_BIZ_WX_PAY_CREATE_FAIL);
|
||||
|
||||
//return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "", PayConstant.RETURN_VALUE_FAIL, PayEnum.ERR_0001));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 构建微信统一下单请求数据
|
||||
* @param payOrder
|
||||
* @param wxPayConfig
|
||||
* @return
|
||||
*/
|
||||
WxPayUnifiedOrderRequest buildUnifiedOrderRequest(PayOrder payOrder, WxPayConfig wxPayConfig) {
|
||||
String tradeType = wxPayConfig.getTradeType();
|
||||
String payOrderId = payOrder.getPayOrderId();
|
||||
Integer totalFee = payOrder.getAmount().intValue();// 支付金额,单位分
|
||||
String deviceInfo = payOrder.getDevice();
|
||||
String body = payOrder.getBody();
|
||||
String detail = null;
|
||||
String attach = null;
|
||||
String outTradeNo = payOrderId;
|
||||
String feeType = "CNY";
|
||||
String spBillCreateIP = payOrder.getClientIp();
|
||||
String timeStart = null;
|
||||
String timeExpire = null;
|
||||
String goodsTag = null;
|
||||
String notifyUrl = wxPayConfig.getNotifyUrl();
|
||||
String productId = null;
|
||||
if(tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_NATIVE)) productId = JSON.parseObject(payOrder.getExtra()).getString("productId");
|
||||
String limitPay = null;
|
||||
String openId = null;
|
||||
if(tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_JSPAI)) openId = JSON.parseObject(payOrder.getExtra()).getString("openId");
|
||||
String sceneInfo = null;
|
||||
if(tradeType.equals(PayConstant.WxConstant.TRADE_TYPE_MWEB)) sceneInfo = JSON.parseObject(payOrder.getExtra()).getString("sceneInfo");
|
||||
// 微信统一下单请求对象
|
||||
WxPayUnifiedOrderRequest request = new WxPayUnifiedOrderRequest();
|
||||
request.setDeviceInfo(deviceInfo);
|
||||
request.setBody(body);
|
||||
request.setDetail(detail);
|
||||
request.setAttach(attach);
|
||||
request.setOutTradeNo(outTradeNo);
|
||||
request.setFeeType(feeType);
|
||||
request.setTotalFee(totalFee);
|
||||
request.setSpbillCreateIp(spBillCreateIP);
|
||||
request.setTimeStart(timeStart);
|
||||
request.setTimeExpire(timeExpire);
|
||||
request.setGoodsTag(goodsTag);
|
||||
request.setNotifyURL(notifyUrl);
|
||||
request.setTradeType(tradeType);
|
||||
request.setProductId(productId);
|
||||
request.setLimitPay(limitPay);
|
||||
request.setOpenid(openId);
|
||||
request.setSceneInfo(sceneInfo);
|
||||
|
||||
return request;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
package org.xxpay.dubbo.service.impl;
|
||||
|
||||
import com.alibaba.dubbo.config.annotation.Service;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.xxpay.common.domain.BaseParam;
|
||||
import org.xxpay.common.enumm.RetEnum;
|
||||
import org.xxpay.common.util.JsonUtil;
|
||||
import org.xxpay.common.util.MyLog;
|
||||
import org.xxpay.common.util.ObjectValidUtil;
|
||||
import org.xxpay.common.util.RpcUtil;
|
||||
import org.xxpay.dal.dao.mapper.PayChannelMapper;
|
||||
import org.xxpay.dal.dao.model.PayChannel;
|
||||
import org.xxpay.dubbo.api.service.IPayChannelService;
|
||||
import org.xxpay.dubbo.service.BaseService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/8
|
||||
* @description:
|
||||
*/
|
||||
@Service(version = "1.0.0")
|
||||
public class PayChannelServiceImpl extends BaseService implements IPayChannelService {
|
||||
|
||||
private static final MyLog _log = MyLog.getLog(PayChannelServiceImpl.class);
|
||||
|
||||
@Override
|
||||
public Map selectPayChannel(String jsonParam) {
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("查询支付渠道信息失败, {}. jsonParam={}", RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
String mchId = baseParam.isNullValue("mchId") ? null : bizParamMap.get("mchId").toString();
|
||||
String channelId = baseParam.isNullValue("channelId") ? null : bizParamMap.get("channelId").toString();
|
||||
if (ObjectValidUtil.isInvalid(mchId, channelId)) {
|
||||
_log.warn("查询支付渠道信息失败, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
PayChannel payChannel = super.baseSelectPayChannel(mchId, channelId);
|
||||
if(payChannel == null) return RpcUtil.createFailResult(baseParam, RetEnum.RET_BIZ_DATA_NOT_EXISTS);
|
||||
String jsonResult = JsonUtil.object2Json(payChannel);
|
||||
return RpcUtil.createBizResult(baseParam, jsonResult);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,174 @@
|
|||
package org.xxpay.dubbo.service.impl;
|
||||
|
||||
import com.alibaba.dubbo.config.annotation.Service;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.xxpay.common.domain.BaseParam;
|
||||
import org.xxpay.common.enumm.RetEnum;
|
||||
import org.xxpay.common.util.*;
|
||||
import org.xxpay.dal.dao.model.PayOrder;
|
||||
import org.xxpay.dubbo.api.service.IPayOrderService;
|
||||
import org.xxpay.dubbo.service.BaseService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/8
|
||||
* @description:
|
||||
*/
|
||||
@Service(version = "1.0.0")
|
||||
public class PayOrderServiceImpl extends BaseService implements IPayOrderService {
|
||||
|
||||
private static final MyLog _log = MyLog.getLog(PayOrderServiceImpl.class);
|
||||
|
||||
@Override
|
||||
public Map createPayOrder(String jsonParam) {
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("新增支付订单失败, {}. jsonParam={}", RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
JSONObject payOrderObj = baseParam.isNullValue("payOrder") ? null : JSONObject.parseObject(bizParamMap.get("payOrder").toString());
|
||||
if(payOrderObj == null) {
|
||||
_log.warn("新增支付订单失败, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
PayOrder payOrder = BeanConvertUtils.map2Bean(payOrderObj, PayOrder.class);
|
||||
if(payOrder == null) {
|
||||
_log.warn("新增支付订单失败, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
int result = super.baseCreatePayOrder(payOrder);
|
||||
return RpcUtil.createBizResult(baseParam, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map selectPayOrder(String jsonParam) {
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("根据支付订单号查询支付订单失败, {}. jsonParam={}", RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
String payOrderId = baseParam.isNullValue("payOrderId") ? null : bizParamMap.get("payOrderId").toString();
|
||||
if (ObjectValidUtil.isInvalid(payOrderId)) {
|
||||
_log.warn("根据支付订单号查询支付订单失败, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
PayOrder payOrder = super.baseSelectPayOrder(payOrderId);
|
||||
if(payOrder == null) return RpcUtil.createFailResult(baseParam, RetEnum.RET_BIZ_DATA_NOT_EXISTS);
|
||||
String jsonResult = JsonUtil.object2Json(payOrder);
|
||||
return RpcUtil.createBizResult(baseParam, jsonResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map selectPayOrderByMchIdAndPayOrderId(String jsonParam) {
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("根据商户号和支付订单号查询支付订单失败, {}. jsonParam={}", RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
String mchId = baseParam.isNullValue("mchId") ? null : bizParamMap.get("mchId").toString();
|
||||
String payOrderId = baseParam.isNullValue("payOrderId") ? null : bizParamMap.get("payOrderId").toString();
|
||||
if (ObjectValidUtil.isInvalid(mchId, payOrderId)) {
|
||||
_log.warn("根据商户号和支付订单号查询支付订单失败, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
PayOrder payOrder = super.baseSelectPayOrderByMchIdAndPayOrderId(mchId, payOrderId);
|
||||
if(payOrder == null) return RpcUtil.createFailResult(baseParam, RetEnum.RET_BIZ_DATA_NOT_EXISTS);
|
||||
String jsonResult = JsonUtil.object2Json(payOrder);
|
||||
return RpcUtil.createBizResult(baseParam, jsonResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map selectPayOrderByMchIdAndMchOrderNo(String jsonParam) {
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("根据商户号和商户订单号查询支付订单失败, {}. jsonParam={}", RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
String mchId = baseParam.isNullValue("mchId") ? null : bizParamMap.get("mchId").toString();
|
||||
String mchOrderNo = baseParam.isNullValue("mchOrderNo") ? null : bizParamMap.get("mchOrderNo").toString();
|
||||
if (ObjectValidUtil.isInvalid(mchId, mchOrderNo)) {
|
||||
_log.warn("根据商户号和商户订单号查询支付订单失败, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
PayOrder payOrder = super.baseSelectPayOrderByMchIdAndMchOrderNo(mchId, mchOrderNo);
|
||||
if(payOrder == null) return RpcUtil.createFailResult(baseParam, RetEnum.RET_BIZ_DATA_NOT_EXISTS);
|
||||
String jsonResult = JsonUtil.object2Json(payOrder);
|
||||
return RpcUtil.createBizResult(baseParam, jsonResult);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map updateStatus4Ing(String jsonParam) {
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("修改支付订单状态为支付中失败, {}. jsonParam={}", RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
String payOrderId = baseParam.isNullValue("payOrderId") ? null : bizParamMap.get("payOrderId").toString();
|
||||
String channelOrderNo = baseParam.isNullValue("channelOrderNo") ? null : bizParamMap.get("channelOrderNo").toString();
|
||||
if (ObjectValidUtil.isInvalid(payOrderId, channelOrderNo)) {
|
||||
_log.warn("修改支付订单状态为支付中失败, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
int result = super.baseUpdateStatus4Ing(payOrderId, channelOrderNo);
|
||||
return RpcUtil.createBizResult(baseParam, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map updateStatus4Success(String jsonParam) {
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("修改支付订单状态为支付成功失败, {}. jsonParam={}", RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
String payOrderId = baseParam.isNullValue("payOrderId") ? null : bizParamMap.get("payOrderId").toString();
|
||||
if (ObjectValidUtil.isInvalid(payOrderId)) {
|
||||
_log.warn("修改支付订单状态为支付成功失败, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
int result = super.baseUpdateStatus4Success(payOrderId);
|
||||
return RpcUtil.createBizResult(baseParam, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map updateStatus4Complete(String jsonParam) {
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("修改支付订单状态为支付完成失败, {}. jsonParam={}", RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
String payOrderId = baseParam.isNullValue("payOrderId") ? null : bizParamMap.get("payOrderId").toString();
|
||||
if (ObjectValidUtil.isInvalid(payOrderId)) {
|
||||
_log.warn("修改支付订单状态为支付完成失败, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
int result = super.baseUpdateStatus4Complete(payOrderId);
|
||||
return RpcUtil.createBizResult(baseParam, result);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map updateNotify(String jsonParam) {
|
||||
BaseParam baseParam = JsonUtil.getObjectFromJson(jsonParam, BaseParam.class);
|
||||
Map<String, Object> bizParamMap = baseParam.getBizParamMap();
|
||||
if (ObjectValidUtil.isInvalid(bizParamMap)) {
|
||||
_log.warn("修改支付订单通知次数失败, {}. jsonParam={}", RetEnum.RET_PARAM_NOT_FOUND.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_NOT_FOUND);
|
||||
}
|
||||
String payOrderId = baseParam.isNullValue("payOrderId") ? null : bizParamMap.get("payOrderId").toString();
|
||||
Byte count = baseParam.isNullValue("count") ? null : Byte.parseByte(bizParamMap.get("count").toString());
|
||||
if (ObjectValidUtil.isInvalid(payOrderId, count)) {
|
||||
_log.warn("修改支付订单通知次数失败, {}. jsonParam={}", RetEnum.RET_PARAM_INVALID.getMessage(), jsonParam);
|
||||
return RpcUtil.createFailResult(baseParam, RetEnum.RET_PARAM_INVALID);
|
||||
}
|
||||
int result = super.baseUpdateNotify(payOrderId, count);
|
||||
return RpcUtil.createBizResult(baseParam, result);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,190 @@
|
|||
package org.xxpay.dubbo.service.mq;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.activemq.ScheduledMessage;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jms.annotation.JmsListener;
|
||||
import org.springframework.jms.core.JmsTemplate;
|
||||
import org.springframework.jms.core.MessageCreator;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.xxpay.common.util.MyLog;
|
||||
import org.xxpay.dubbo.service.BaseService;
|
||||
|
||||
import javax.jms.*;
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
import javax.net.ssl.SSLContext;
|
||||
import javax.net.ssl.TrustManager;
|
||||
import javax.net.ssl.X509TrustManager;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.InputStreamReader;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.URL;
|
||||
import java.security.cert.CertificateException;
|
||||
import java.security.cert.X509Certificate;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
|
||||
/**
|
||||
* @Description: 业务通知MQ实现
|
||||
* @author dingzhiwei jmdhappy@126.com
|
||||
* @date 2017-07-05
|
||||
* @version V1.0
|
||||
* @Copyright: www.xxpay.org
|
||||
*/
|
||||
@Component
|
||||
public class Mq4PayNotify extends BaseService {
|
||||
|
||||
@Autowired
|
||||
private Queue payNotifyQueue;
|
||||
|
||||
@Autowired
|
||||
private JmsTemplate jmsTemplate;
|
||||
|
||||
private static final MyLog _log = MyLog.getLog(Mq4PayNotify.class);
|
||||
|
||||
public void send(String msg) {
|
||||
_log.info("发送MQ消息:msg={}", msg);
|
||||
this.jmsTemplate.convertAndSend(this.payNotifyQueue, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发送延迟消息
|
||||
* @param msg
|
||||
* @param delay
|
||||
*/
|
||||
public void send(String msg, long delay) {
|
||||
_log.info("发送MQ延时消息:msg={},delay={}", msg, delay);
|
||||
jmsTemplate.send(this.payNotifyQueue, new MessageCreator() {
|
||||
public Message createMessage(Session session) throws JMSException {
|
||||
TextMessage tm = session.createTextMessage(msg);
|
||||
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_DELAY, delay);
|
||||
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_PERIOD, 1*1000);
|
||||
tm.setLongProperty(ScheduledMessage.AMQ_SCHEDULED_REPEAT, 1);
|
||||
return tm;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static class TrustAnyTrustManager implements X509TrustManager {
|
||||
|
||||
public void checkClientTrusted(X509Certificate[] chain, String authType)
|
||||
throws CertificateException {
|
||||
}
|
||||
|
||||
public void checkServerTrusted(X509Certificate[] chain, String authType)
|
||||
throws CertificateException {
|
||||
}
|
||||
|
||||
public X509Certificate[] getAcceptedIssuers() {
|
||||
return new X509Certificate[] {};
|
||||
}
|
||||
}
|
||||
|
||||
@JmsListener(destination = MqConfig.PAY_NOTIFY_QUEUE_NAME)
|
||||
public void receive(String msg) {
|
||||
_log.info("do notify task, msg={}", msg);
|
||||
JSONObject msgObj = JSON.parseObject(msg);
|
||||
String respUrl = msgObj.getString("url");
|
||||
String orderId = msgObj.getString("orderId");
|
||||
int count = msgObj.getInteger("count");
|
||||
if(StringUtils.isEmpty(respUrl)) {
|
||||
_log.warn("notify url is empty. respUrl={}", respUrl);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
URL console = new URL(respUrl);
|
||||
_log.info("==>MQ通知业务系统开始[orderId:{}][count:{}][time:{}]", orderId, count, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||||
if("https".equals(console.getProtocol())) {
|
||||
SSLContext sc = SSLContext.getInstance("SSL");
|
||||
sc.init(null, new TrustManager[] { new TrustAnyTrustManager() },
|
||||
new java.security.SecureRandom());
|
||||
HttpsURLConnection con = (HttpsURLConnection) console.openConnection();
|
||||
con.setSSLSocketFactory(sc.getSocketFactory());
|
||||
con.setRequestMethod("POST");
|
||||
con.setDoInput(true);
|
||||
con.setDoOutput(true);
|
||||
con.setUseCaches(false);
|
||||
con.setConnectTimeout(10 * 1000);
|
||||
con.setReadTimeout(5 * 1000);
|
||||
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()), 1024*1024);
|
||||
while (true) {
|
||||
String line = in.readLine();
|
||||
if (line == null) {
|
||||
break;
|
||||
}
|
||||
sb.append(line);
|
||||
}
|
||||
in.close();
|
||||
}else if("http".equals(console.getProtocol())) {
|
||||
HttpURLConnection con = (HttpURLConnection) console.openConnection();
|
||||
con.setRequestMethod("POST");
|
||||
con.setDoInput(true);
|
||||
con.setDoOutput(true);
|
||||
con.setUseCaches(false);
|
||||
con.setConnectTimeout(10 * 1000);
|
||||
con.setReadTimeout(5 * 1000);
|
||||
con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
|
||||
BufferedReader in = new BufferedReader(new InputStreamReader(con.getInputStream()), 1024*1024);
|
||||
while (true) {
|
||||
String line = in.readLine();
|
||||
if (line == null) {
|
||||
break;
|
||||
}
|
||||
sb.append(line);
|
||||
}
|
||||
in.close();
|
||||
}else {
|
||||
_log.error("not do protocol. protocol=%s", console.getProtocol());
|
||||
return;
|
||||
}
|
||||
_log.info("<==MQ通知业务系统结束[orderId:{}][count:{}][time:{}]", orderId, count, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||||
// 验证结果
|
||||
_log.info("notify response , OrderID={}", orderId);
|
||||
if(sb.toString().trim().equalsIgnoreCase("success")){
|
||||
//_log.info("{} notify success, url:{}", _notifyInfo.getBusiId(), respUrl);
|
||||
//修改订单表
|
||||
try {
|
||||
int result = super.baseUpdateStatus4Complete(orderId);
|
||||
_log.info("修改payOrderId={},订单状态为处理完成->{}", orderId, result == 1 ? "成功" : "失败");
|
||||
} catch (Exception e) {
|
||||
_log.error(e, "修改订单状态为处理完成异常");
|
||||
}
|
||||
// 修改通知次数
|
||||
try {
|
||||
int result = super.baseUpdateNotify(orderId, (byte) 1);
|
||||
_log.info("修改payOrderId={},通知业务系统次数->{}", orderId, result == 1 ? "成功" : "失败");
|
||||
}catch (Exception e) {
|
||||
_log.error(e, "修改通知次数异常");
|
||||
}
|
||||
return ; // 通知成功结束
|
||||
}else {
|
||||
// 通知失败,延时再通知
|
||||
int cnt = count+1;
|
||||
_log.info("notify count={}", cnt);
|
||||
// 修改通知次数
|
||||
try {
|
||||
int result = super.baseUpdateNotify(orderId, (byte) cnt);
|
||||
_log.info("修改payOrderId={},通知业务系统次数->{}", orderId, result == 1 ? "成功" : "失败");
|
||||
}catch (Exception e) {
|
||||
_log.error(e, "修改通知次数异常");
|
||||
}
|
||||
|
||||
if (cnt > 5) {
|
||||
_log.info("notify count>5 stop. url={}", respUrl);
|
||||
return ;
|
||||
}
|
||||
msgObj.put("count", cnt);
|
||||
this.send(msgObj.toJSONString(), cnt * 60 * 1000);
|
||||
}
|
||||
_log.warn("notify failed. url:{}, response body:{}", respUrl, sb.toString());
|
||||
} catch(Exception e) {
|
||||
_log.info("<==MQ通知业务系统结束[orderId:{}][count:{}][time:{}]", orderId, count, new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date()));
|
||||
_log.error(e, "notify exception. url:%s", respUrl);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,26 @@
|
|||
package org.xxpay.dubbo.service.mq;
|
||||
|
||||
import org.apache.activemq.command.ActiveMQQueue;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import javax.jms.Queue;
|
||||
|
||||
/**
|
||||
* @Description:
|
||||
* @author dingzhiwei jmdhappy@126.com
|
||||
* @date 2017-07-05
|
||||
* @version V1.0
|
||||
* @Copyright: www.xxpay.org
|
||||
*/
|
||||
@Configuration
|
||||
public class MqConfig {
|
||||
|
||||
public static final String PAY_NOTIFY_QUEUE_NAME = "pay.notify.queue";
|
||||
|
||||
@Bean
|
||||
public Queue payNotifyQueue() {
|
||||
return new ActiveMQQueue(PAY_NOTIFY_QUEUE_NAME);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,47 @@
|
|||
spring:
|
||||
dubbo:
|
||||
application:
|
||||
name: xxpay4dubbo-service
|
||||
registry:
|
||||
address: zookeeper://127.0.0.1:2181
|
||||
protocol:
|
||||
name: dubbo
|
||||
port: 20880
|
||||
scan: org.xxpay.dubbo
|
||||
datasource:
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
driver-class-name: com.mysql.jdbc.Driver
|
||||
url: jdbc:mysql://127.0.0.1:3306/xxpaydb?useUnicode=true&characterEncoding=utf-8&autoReconnect=true&useSSL=false
|
||||
username: xxpay
|
||||
password: xxpay
|
||||
initialSize: 5 # 初始化大小
|
||||
minIdle: 5 # 最小
|
||||
maxActive: 20 # 最大
|
||||
maxWait: 60000 # 获取连接等待超时的时间
|
||||
timeBetweenEvictionRunsMillis: 60000 # 配置间隔多久才进行一次检测,检测需要关闭的空闲连接,单位是毫秒
|
||||
minEvictableIdleTimeMillis: 300000 # 配置一个连接在池中最小生存的时间,单位是毫秒
|
||||
validationQuery: SELECT 1 FROM DUAL
|
||||
testWhileIdle: true
|
||||
testOnBorrow: false
|
||||
testOnReturn: false
|
||||
poolPreparedStatements: true # 打开PSCache
|
||||
maxPoolPreparedStatementPerConnectionSize: 20 # 指定每个连接上PSCache的大小
|
||||
filters: stat,wall,log4j # 配置监控统计拦截的filters,去掉后监控界面sql无法统计,'wall'用于防火墙
|
||||
connectionProperties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000 # 通过connectProperties属性来打开mergeSql功能;慢SQL记录
|
||||
profiles:
|
||||
active: prod
|
||||
|
||||
activemq:
|
||||
broker-url: failover:(tcp://127.0.0.1:61616?wireFormat.maxInactivityDuration=0)
|
||||
in-memory: true
|
||||
|
||||
logging:
|
||||
file: ./log/xxpay4dubbo-service.log
|
||||
|
||||
config:
|
||||
ali:
|
||||
notify_url: http://xxpay.nat100.top/notify/pay/aliPayNotifyRes.htm
|
||||
return_url: http://www.xxpay.org
|
||||
wx:
|
||||
certRootPath: /Users/dingzhiwei/java/tmp/cert
|
||||
notifyUrl: http://xxpay.nat100.top/notify/pay/wxPayNotifyRes.htm
|
||||
Binary file not shown.
|
|
@ -0,0 +1,49 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<groupId>org.xxpay</groupId>
|
||||
<artifactId>xxpay4dubbo-web</artifactId>
|
||||
<version>1.0.0</version>
|
||||
<packaging>jar</packaging>
|
||||
<name>xxpay4dubbo-web</name>
|
||||
<description>xxpay4dubbo-web</description>
|
||||
|
||||
<parent>
|
||||
<groupId>org.xxpay</groupId>
|
||||
<artifactId>xxpay4dubbo</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>org.xxpay</groupId>
|
||||
<artifactId>xxpay4dubbo-api</artifactId>
|
||||
<version>1.0.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.dubbo.springboot</groupId>
|
||||
<artifactId>spring-boot-starter-dubbo</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>commons-io</groupId>
|
||||
<artifactId>commons-io</artifactId>
|
||||
<version>2.4</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-maven-plugin</artifactId>
|
||||
<version>${springboot.version}</version>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</project>
|
||||
|
|
@ -0,0 +1,16 @@
|
|||
package org.xxpay.dubbo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@SpringBootApplication
|
||||
@ComponentScan(basePackages={"org.xxpay"})
|
||||
public class XxPayDubboWebAppliaction {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(XxPayDubboWebAppliaction.class, args);
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,75 @@
|
|||
package org.xxpay.dubbo.web.ctrl;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.xxpay.common.constant.PayConstant;
|
||||
import org.xxpay.common.util.MyLog;
|
||||
import org.xxpay.dubbo.web.service.NotifyPayService;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 接收处理支付宝通知
|
||||
* @author dingzhiwei jmdhappy@126.com
|
||||
* @date 2017-07-05
|
||||
* @version V1.0
|
||||
* @Copyright: www.xxpay.org
|
||||
*/
|
||||
@RestController
|
||||
public class Notify4AliPayController {
|
||||
|
||||
private static final MyLog _log = MyLog.getLog(Notify4AliPayController.class);
|
||||
|
||||
@Autowired
|
||||
private NotifyPayService notifyPayService;
|
||||
|
||||
/**
|
||||
* 支付宝移动支付后台通知响应
|
||||
* @param request
|
||||
* @return
|
||||
* @throws ServletException
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping(value = "/notify/pay/aliPayNotifyRes.htm")
|
||||
@ResponseBody
|
||||
public String aliPayNotifyRes(HttpServletRequest request) throws ServletException, IOException {
|
||||
_log.info("====== 开始接收支付宝支付回调通知 ======");
|
||||
String notifyRes = doAliPayRes(request);
|
||||
_log.info("响应给支付宝:{}", notifyRes);
|
||||
_log.info("====== 完成接收支付宝支付回调通知 ======");
|
||||
return notifyRes;
|
||||
}
|
||||
|
||||
public String doAliPayRes(HttpServletRequest request) throws ServletException, IOException {
|
||||
String logPrefix = "【支付宝支付回调通知】";
|
||||
//获取支付宝POST过来反馈信息
|
||||
Map<String,String> params = new HashMap<String,String>();
|
||||
Map requestParams = request.getParameterMap();
|
||||
for (Iterator iter = requestParams.keySet().iterator(); iter.hasNext();) {
|
||||
String name = (String) iter.next();
|
||||
String[] values = (String[]) requestParams.get(name);
|
||||
String valueStr = "";
|
||||
for (int i = 0; i < values.length; i++) {
|
||||
valueStr = (i == values.length - 1) ? valueStr + values[i]
|
||||
: valueStr + values[i] + ",";
|
||||
}
|
||||
//乱码解决,这段代码在出现乱码时使用。如果mysign和sign不相等也可以使用这段代码转化
|
||||
//valueStr = new String(valueStr.getBytes("ISO-8859-1"), "gbk");
|
||||
params.put(name, valueStr);
|
||||
}
|
||||
_log.info("{}通知请求数据:reqStr={}", logPrefix, params);
|
||||
if(params.isEmpty()) {
|
||||
_log.error("{}请求参数为空", logPrefix);
|
||||
return PayConstant.RETURN_ALIPAY_VALUE_FAIL;
|
||||
}
|
||||
return notifyPayService.doAliPayNotify(params);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,54 @@
|
|||
package org.xxpay.dubbo.web.ctrl;
|
||||
|
||||
import org.apache.commons.io.IOUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.xxpay.common.util.MyLog;
|
||||
import org.xxpay.dubbo.web.service.NotifyPayService;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* @Description: 接收处理微信通知
|
||||
* @author dingzhiwei jmdhappy@126.com
|
||||
* @date 2017-07-05
|
||||
* @version V1.0
|
||||
* @Copyright: www.xxpay.org
|
||||
*/
|
||||
@RestController
|
||||
public class Notify4WxPayController {
|
||||
|
||||
private static final MyLog _log = MyLog.getLog(Notify4WxPayController.class);
|
||||
|
||||
@Autowired
|
||||
private NotifyPayService notifyPayService;
|
||||
|
||||
/**
|
||||
* 微信支付(统一下单接口)后台通知响应
|
||||
* @param request
|
||||
* @return
|
||||
* @throws ServletException
|
||||
* @throws IOException
|
||||
*/
|
||||
@RequestMapping("/notify/pay/wxPayNotifyRes.htm")
|
||||
@ResponseBody
|
||||
public String wxPayNotifyRes(HttpServletRequest request) throws ServletException, IOException {
|
||||
_log.info("====== 开始接收微信支付回调通知 ======");
|
||||
String notifyRes = doWxPayRes(request);
|
||||
_log.info("响应给微信:{}", notifyRes);
|
||||
_log.info("====== 完成接收微信支付回调通知 ======");
|
||||
return notifyRes;
|
||||
}
|
||||
|
||||
public String doWxPayRes(HttpServletRequest request) throws ServletException, IOException {
|
||||
String logPrefix = "【微信支付回调通知】";
|
||||
String xmlResult = IOUtils.toString(request.getInputStream(), request.getCharacterEncoding());
|
||||
_log.info("{}通知请求数据:reqStr={}", logPrefix, xmlResult);
|
||||
return notifyPayService.doWxPayNotify(xmlResult);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,268 @@
|
|||
package org.xxpay.dubbo.web.ctrl;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.commons.lang3.math.NumberUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.xxpay.common.constant.PayConstant;
|
||||
import org.xxpay.common.util.MyLog;
|
||||
import org.xxpay.common.util.MySeq;
|
||||
import org.xxpay.common.util.XXPayUtil;
|
||||
import org.xxpay.dubbo.web.service.MchInfoService;
|
||||
import org.xxpay.dubbo.web.service.PayChannelService;
|
||||
import org.xxpay.dubbo.web.service.PayOrderService;
|
||||
|
||||
/**
|
||||
* @Description: 支付订单,包括:统一下单,订单查询,补单等接口
|
||||
* @author dingzhiwei jmdhappy@126.com
|
||||
* @date 2017-07-05
|
||||
* @version V1.0
|
||||
* @Copyright: www.xxpay.org
|
||||
*/
|
||||
@RestController
|
||||
public class PayOrderController {
|
||||
|
||||
private final MyLog _log = MyLog.getLog(PayOrderController.class);
|
||||
|
||||
@Autowired
|
||||
private PayOrderService payOrderService;
|
||||
|
||||
@Autowired
|
||||
private PayChannelService payChannelService;
|
||||
|
||||
@Autowired
|
||||
private MchInfoService mchInfoService;
|
||||
|
||||
/**
|
||||
* 统一下单接口:
|
||||
* 1)先验证接口参数以及签名信息
|
||||
* 2)验证通过创建支付订单
|
||||
* 3)根据商户选择渠道,调用支付服务进行下单
|
||||
* 4)返回下单数据
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/api/pay/create_order")
|
||||
public String payOrder(@RequestParam String params) {
|
||||
_log.info("###### 开始接收商户统一下单请求 ######");
|
||||
String logPrefix = "【商户统一下单】";
|
||||
try {
|
||||
JSONObject po = JSONObject.parseObject(params);
|
||||
JSONObject payContext = new JSONObject();
|
||||
JSONObject payOrder = null;
|
||||
// 验证参数有效性
|
||||
Object object = validateParams(po, payContext);
|
||||
if (object instanceof String) {
|
||||
_log.info("{}参数校验不通过:{}", logPrefix, object);
|
||||
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, object.toString(), null, null));
|
||||
}
|
||||
if (object instanceof JSONObject) payOrder = (JSONObject) object;
|
||||
if(payOrder == null) return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "支付中心下单失败", null, null));
|
||||
int result = payOrderService.createPayOrder(payOrder);
|
||||
_log.info("{}创建支付订单,结果:{}", logPrefix, result);
|
||||
if(result != 1) {
|
||||
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "创建支付订单失败", null, null));
|
||||
}
|
||||
String channelId = payOrder.getString("channelId");
|
||||
switch (channelId) {
|
||||
case PayConstant.PAY_CHANNEL_WX_APP :
|
||||
return payOrderService.doWxPayReq(PayConstant.WxConstant.TRADE_TYPE_APP, payOrder, payContext.getString("resKey"));
|
||||
case PayConstant.PAY_CHANNEL_WX_JSAPI :
|
||||
return payOrderService.doWxPayReq(PayConstant.WxConstant.TRADE_TYPE_JSPAI, payOrder, payContext.getString("resKey"));
|
||||
case PayConstant.PAY_CHANNEL_WX_NATIVE :
|
||||
return payOrderService.doWxPayReq(PayConstant.WxConstant.TRADE_TYPE_NATIVE, payOrder, payContext.getString("resKey"));
|
||||
case PayConstant.PAY_CHANNEL_WX_MWEB :
|
||||
return payOrderService.doWxPayReq(PayConstant.WxConstant.TRADE_TYPE_MWEB, payOrder, payContext.getString("resKey"));
|
||||
case PayConstant.PAY_CHANNEL_ALIPAY_MOBILE :
|
||||
return payOrderService.doAliPayReq(channelId, payOrder, payContext.getString("resKey"));
|
||||
case PayConstant.PAY_CHANNEL_ALIPAY_PC :
|
||||
return payOrderService.doAliPayReq(channelId, payOrder, payContext.getString("resKey"));
|
||||
case PayConstant.PAY_CHANNEL_ALIPAY_WAP :
|
||||
return payOrderService.doAliPayReq(channelId, payOrder, payContext.getString("resKey"));
|
||||
case PayConstant.PAY_CHANNEL_ALIPAY_QR :
|
||||
return payOrderService.doAliPayReq(channelId, payOrder, payContext.getString("resKey"));
|
||||
default:
|
||||
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "不支持的支付渠道类型[channelId="+channelId+"]", null, null));
|
||||
}
|
||||
}catch (Exception e) {
|
||||
_log.error(e, "");
|
||||
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "支付中心系统异常", null, null));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证创建订单请求参数,参数通过返回JSONObject对象,否则返回错误文本信息
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
private Object validateParams(JSONObject params, JSONObject payContext) {
|
||||
// 验证请求参数,参数有问题返回错误提示
|
||||
String errorMessage;
|
||||
// 支付参数
|
||||
String mchId = params.getString("mchId"); // 商户ID
|
||||
String mchOrderNo = params.getString("mchOrderNo"); // 商户订单号
|
||||
String channelId = params.getString("channelId"); // 渠道ID
|
||||
String amount = params.getString("amount"); // 支付金额(单位分)
|
||||
String currency = params.getString("currency"); // 币种
|
||||
String clientIp = params.getString("clientIp"); // 客户端IP
|
||||
String device = params.getString("device"); // 设备
|
||||
String extra = params.getString("extra"); // 特定渠道发起时额外参数
|
||||
String param1 = params.getString("param1"); // 扩展参数1
|
||||
String param2 = params.getString("param2"); // 扩展参数2
|
||||
String notifyUrl = params.getString("notifyUrl"); // 支付结果回调URL
|
||||
String sign = params.getString("sign"); // 签名
|
||||
String subject = params.getString("subject"); // 商品主题
|
||||
String body = params.getString("body"); // 商品描述信息
|
||||
// 验证请求参数有效性(必选项)
|
||||
if(StringUtils.isBlank(mchId)) {
|
||||
errorMessage = "request params[mchId] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
if(StringUtils.isBlank(mchOrderNo)) {
|
||||
errorMessage = "request params[mchOrderNo] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
if(StringUtils.isBlank(channelId)) {
|
||||
errorMessage = "request params[channelId] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
if(!NumberUtils.isNumber(amount)) {
|
||||
errorMessage = "request params[amount] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
if(StringUtils.isBlank(currency)) {
|
||||
errorMessage = "request params[currency] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
if(StringUtils.isBlank(notifyUrl)) {
|
||||
errorMessage = "request params[notifyUrl] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
if(StringUtils.isBlank(subject)) {
|
||||
errorMessage = "request params[subject] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
if(StringUtils.isBlank(body)) {
|
||||
errorMessage = "request params[body] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
// 根据不同渠道,判断extra参数
|
||||
if(PayConstant.PAY_CHANNEL_WX_JSAPI.equalsIgnoreCase(channelId)) {
|
||||
if(StringUtils.isEmpty(extra)) {
|
||||
errorMessage = "request params[extra] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
JSONObject extraObject = JSON.parseObject(extra);
|
||||
String openId = extraObject.getString("openId");
|
||||
if(StringUtils.isBlank(openId)) {
|
||||
errorMessage = "request params[extra.openId] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
}else if(PayConstant.PAY_CHANNEL_WX_NATIVE.equalsIgnoreCase(channelId)) {
|
||||
if(StringUtils.isEmpty(extra)) {
|
||||
errorMessage = "request params[extra] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
JSONObject extraObject = JSON.parseObject(extra);
|
||||
String productId = extraObject.getString("productId");
|
||||
if(StringUtils.isBlank(productId)) {
|
||||
errorMessage = "request params[extra.productId] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
}else if(PayConstant.PAY_CHANNEL_WX_MWEB.equalsIgnoreCase(channelId)) {
|
||||
if(StringUtils.isEmpty(extra)) {
|
||||
errorMessage = "request params[extra] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
JSONObject extraObject = JSON.parseObject(extra);
|
||||
String productId = extraObject.getString("sceneInfo");
|
||||
if(StringUtils.isBlank(productId)) {
|
||||
errorMessage = "request params[extra.sceneInfo] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
if(StringUtils.isBlank(clientIp)) {
|
||||
errorMessage = "request params[clientIp] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
}
|
||||
|
||||
// 签名信息
|
||||
if (StringUtils.isEmpty(sign)) {
|
||||
errorMessage = "request params[sign] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
// 查询商户信息
|
||||
JSONObject mchInfo = mchInfoService.getByMchId(mchId);
|
||||
if(mchInfo == null) {
|
||||
errorMessage = "Can't found mchInfo[mchId="+mchId+"] record in db.";
|
||||
return errorMessage;
|
||||
}
|
||||
if(mchInfo.getByte("state") != 1) {
|
||||
errorMessage = "mchInfo not available [mchId="+mchId+"] record in db.";
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
String reqKey = mchInfo.getString("reqKey");
|
||||
if (StringUtils.isBlank(reqKey)) {
|
||||
errorMessage = "reqKey is null[mchId="+mchId+"] record in db.";
|
||||
return errorMessage;
|
||||
}
|
||||
payContext.put("resKey", mchInfo.getString("resKey"));
|
||||
|
||||
// 查询商户对应的支付渠道
|
||||
JSONObject payChannel = payChannelService.getByMchIdAndChannelId(mchId, channelId);
|
||||
if(payChannel == null) {
|
||||
errorMessage = "Can't found payChannel[channelId="+channelId+",mchId="+mchId+"] record in db.";
|
||||
return errorMessage;
|
||||
}
|
||||
if(payChannel.getByte("state") != 1) {
|
||||
errorMessage = "channel not available [channelId="+channelId+",mchId="+mchId+"]";
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
// 验证签名数据
|
||||
boolean verifyFlag = XXPayUtil.verifyPaySign(params, reqKey);
|
||||
if(!verifyFlag) {
|
||||
errorMessage = "Verify XX pay sign failed.";
|
||||
return errorMessage;
|
||||
}
|
||||
// 验证参数通过,返回JSONObject对象
|
||||
JSONObject payOrder = new JSONObject();
|
||||
payOrder.put("payOrderId", MySeq.getPay());
|
||||
payOrder.put("mchId", mchId);
|
||||
payOrder.put("mchOrderNo", mchOrderNo);
|
||||
payOrder.put("channelId", channelId);
|
||||
payOrder.put("amount", Long.parseLong(amount));
|
||||
payOrder.put("currency", currency);
|
||||
payOrder.put("clientIp", clientIp);
|
||||
payOrder.put("device", device);
|
||||
payOrder.put("subject", subject);
|
||||
payOrder.put("body", body);
|
||||
payOrder.put("extra", extra);
|
||||
payOrder.put("channelMchId", payChannel.getString("channelMchId"));
|
||||
payOrder.put("param1", param1);
|
||||
payOrder.put("param2", param2);
|
||||
payOrder.put("notifyUrl", notifyUrl);
|
||||
return payOrder;
|
||||
}
|
||||
|
||||
String getJsonParam(String[] names, Object[] values) {
|
||||
JSONObject jsonParam = new JSONObject();
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
jsonParam.put(names[i], values[i]);
|
||||
}
|
||||
return jsonParam.toJSONString();
|
||||
}
|
||||
|
||||
String getJsonParam(String name, Object value) {
|
||||
JSONObject jsonParam = new JSONObject();
|
||||
jsonParam.put(name, value);
|
||||
return jsonParam.toJSONString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,135 @@
|
|||
package org.xxpay.dubbo.web.ctrl;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
import org.xxpay.common.constant.PayConstant;
|
||||
import org.xxpay.common.util.MyLog;
|
||||
import org.xxpay.common.util.XXPayUtil;
|
||||
import org.xxpay.dubbo.web.service.MchInfoService;
|
||||
import org.xxpay.dubbo.web.service.PayOrderService;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Description: 支付订单查询
|
||||
* @author dingzhiwei jmdhappy@126.com
|
||||
* @date 2017-08-31
|
||||
* @version V1.0
|
||||
* @Copyright: www.xxpay.org
|
||||
*/
|
||||
@RestController
|
||||
public class QueryPayOrderController {
|
||||
|
||||
private final MyLog _log = MyLog.getLog(QueryPayOrderController.class);
|
||||
|
||||
@Autowired
|
||||
private PayOrderService payOrderService;
|
||||
|
||||
@Autowired
|
||||
private MchInfoService mchInfoService;
|
||||
|
||||
/**
|
||||
* 查询支付订单接口:
|
||||
* 1)先验证接口参数以及签名信息
|
||||
* 2)根据参数查询订单
|
||||
* 3)返回订单数据
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@RequestMapping(value = "/api/pay/query_order")
|
||||
public String queryPayOrder(@RequestParam String params) {
|
||||
_log.info("###### 开始接收商户查询支付订单请求 ######");
|
||||
String logPrefix = "【商户支付订单查询】";
|
||||
try {
|
||||
JSONObject po = JSONObject.parseObject(params);
|
||||
JSONObject payContext = new JSONObject();
|
||||
// 验证参数有效性
|
||||
String errorMessage = validateParams(po, payContext);
|
||||
if (!"success".equalsIgnoreCase(errorMessage)) {
|
||||
_log.warn(errorMessage);
|
||||
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, errorMessage, null, null));
|
||||
}
|
||||
_log.debug("请求参数及签名校验通过");
|
||||
String mchId = po.getString("mchId"); // 商户ID
|
||||
String mchOrderNo = po.getString("mchOrderNo"); // 商户订单号
|
||||
String payOrderId = po.getString("payOrderId"); // 支付订单号
|
||||
String executeNotify = po.getString("executeNotify"); // 是否执行回调
|
||||
JSONObject payOrder = payOrderService.queryPayOrder(mchId, payOrderId, mchOrderNo, executeNotify);
|
||||
_log.info("{}查询支付订单,结果:{}", logPrefix, payOrder);
|
||||
if (payOrder == null) {
|
||||
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "支付订单不存在", null, null));
|
||||
}
|
||||
Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
|
||||
map.put("result", payOrder);
|
||||
_log.info("###### 商户查询订单处理完成 ######");
|
||||
return XXPayUtil.makeRetData(map, payContext.getString("resKey"));
|
||||
}catch (Exception e) {
|
||||
_log.error(e, "");
|
||||
return XXPayUtil.makeRetFail(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_FAIL, "支付中心系统异常", null, null));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证创建订单请求参数,参数通过返回JSONObject对象,否则返回错误文本信息
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
private String validateParams(JSONObject params, JSONObject payContext) {
|
||||
// 验证请求参数,参数有问题返回错误提示
|
||||
String errorMessage;
|
||||
// 支付参数
|
||||
String mchId = params.getString("mchId"); // 商户ID
|
||||
String mchOrderNo = params.getString("mchOrderNo"); // 商户订单号
|
||||
String payOrderId = params.getString("payOrderId"); // 支付订单号
|
||||
|
||||
String sign = params.getString("sign"); // 签名
|
||||
|
||||
// 验证请求参数有效性(必选项)
|
||||
if(StringUtils.isBlank(mchId)) {
|
||||
errorMessage = "request params[mchId] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
if(StringUtils.isBlank(mchOrderNo) && StringUtils.isBlank(payOrderId)) {
|
||||
errorMessage = "request params[mchOrderNo or payOrderId] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
// 签名信息
|
||||
if (StringUtils.isEmpty(sign)) {
|
||||
errorMessage = "request params[sign] error.";
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
// 查询商户信息
|
||||
JSONObject mchInfo = mchInfoService.getByMchId(mchId);
|
||||
if(mchInfo == null) {
|
||||
errorMessage = "Can't found mchInfo[mchId="+mchId+"] record in db.";
|
||||
return errorMessage;
|
||||
}
|
||||
if(mchInfo.getByte("state") != 1) {
|
||||
errorMessage = "mchInfo not available [mchId="+mchId+"] record in db.";
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
String reqKey = mchInfo.getString("reqKey");
|
||||
if (StringUtils.isBlank(reqKey)) {
|
||||
errorMessage = "reqKey is null[mchId="+mchId+"] record in db.";
|
||||
return errorMessage;
|
||||
}
|
||||
payContext.put("resKey", mchInfo.getString("resKey"));
|
||||
|
||||
// 验证签名数据
|
||||
boolean verifyFlag = XXPayUtil.verifyPaySign(params, reqKey);
|
||||
if(!verifyFlag) {
|
||||
errorMessage = "Verify XX pay sign failed.";
|
||||
return errorMessage;
|
||||
}
|
||||
|
||||
return "success";
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,32 @@
|
|||
package org.xxpay.dubbo.web.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.xxpay.common.util.RpcUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/9
|
||||
* @description:
|
||||
*/
|
||||
@Service
|
||||
public class MchInfoService {
|
||||
|
||||
@Autowired
|
||||
private RpcCommonService rpcCommonService;
|
||||
|
||||
public JSONObject getByMchId(String mchId) {
|
||||
Map<String,Object> paramMap = new HashMap<>();
|
||||
paramMap.put("mchId", mchId);
|
||||
String jsonParam = RpcUtil.createBaseParam(paramMap);
|
||||
Map<String, Object> result = rpcCommonService.rpcMchInfoService.selectMchInfo(jsonParam);
|
||||
String s = RpcUtil.mkRet(result);
|
||||
if(s==null) return null;
|
||||
return JSONObject.parseObject(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,43 @@
|
|||
package org.xxpay.dubbo.web.service;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.xxpay.common.constant.PayConstant;
|
||||
import org.xxpay.common.util.RpcUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/10
|
||||
* @description:
|
||||
*/
|
||||
@Service
|
||||
public class NotifyPayService {
|
||||
|
||||
@Autowired
|
||||
private RpcCommonService rpcCommonService;
|
||||
|
||||
public String doAliPayNotify(Map params) {
|
||||
Map<String,Object> paramMap = new HashMap<>();
|
||||
paramMap.put("params", params);
|
||||
String jsonParam = RpcUtil.createBaseParam(paramMap);
|
||||
Map<String, Object> result = rpcCommonService.rpcNotifyPayService.doAliPayNotify(jsonParam);
|
||||
String s = RpcUtil.mkRet(result);
|
||||
if(s == null) {
|
||||
return PayConstant.RETURN_ALIPAY_VALUE_FAIL;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
public String doWxPayNotify(String xmlResult) {
|
||||
Map<String,Object> paramMap = new HashMap<>();
|
||||
paramMap.put("xmlResult", xmlResult);
|
||||
String jsonParam = RpcUtil.createBaseParam(paramMap);
|
||||
// 返回给微信的数据格式已经有service处理(包括正确与错误),肯定会返回result
|
||||
Map<String, Object> result = rpcCommonService.rpcNotifyPayService.doWxPayNotify(jsonParam);
|
||||
return RpcUtil.mkRet(result);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package org.xxpay.dubbo.web.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.xxpay.common.util.RpcUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/9
|
||||
* @description:
|
||||
*/
|
||||
@Service
|
||||
public class PayChannelService {
|
||||
|
||||
@Autowired
|
||||
private RpcCommonService rpcCommonService;
|
||||
|
||||
public JSONObject getByMchIdAndChannelId(String mchId, String channelId) {
|
||||
Map<String,Object> paramMap = new HashMap<>();
|
||||
paramMap.put("mchId", mchId);
|
||||
paramMap.put("channelId", channelId);
|
||||
String jsonParam = RpcUtil.createBaseParam(paramMap);
|
||||
Map<String, Object> result = rpcCommonService.rpcPayChannelService.selectPayChannel(jsonParam);
|
||||
String s = RpcUtil.mkRet(result);
|
||||
if(s == null) return null;
|
||||
return JSONObject.parseObject(s);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,113 @@
|
|||
package org.xxpay.dubbo.web.service;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.xxpay.common.constant.PayConstant;
|
||||
import org.xxpay.common.util.MyLog;
|
||||
import org.xxpay.common.util.RpcUtil;
|
||||
import org.xxpay.common.util.XXPayUtil;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/9
|
||||
* @description:
|
||||
*/
|
||||
@Service
|
||||
public class PayOrderService {
|
||||
|
||||
private static final MyLog _log = MyLog.getLog(PayOrderService.class);
|
||||
|
||||
@Autowired
|
||||
private RpcCommonService rpcCommonService;
|
||||
|
||||
public int createPayOrder(JSONObject payOrder) {
|
||||
Map<String,Object> paramMap = new HashMap<>();
|
||||
paramMap.put("payOrder", payOrder);
|
||||
String jsonParam = RpcUtil.createBaseParam(paramMap);
|
||||
Map<String, Object> result = rpcCommonService.rpcPayOrderService.createPayOrder(jsonParam);
|
||||
String s = RpcUtil.mkRet(result);
|
||||
if(s == null) return 0;
|
||||
return Integer.parseInt(s);
|
||||
}
|
||||
|
||||
public JSONObject queryPayOrder(String mchId, String payOrderId, String mchOrderNo, String executeNotify) {
|
||||
Map<String,Object> paramMap = new HashMap<>();
|
||||
Map<String, Object> result;
|
||||
if(StringUtils.isNotBlank(payOrderId)) {
|
||||
paramMap.put("mchId", mchId);
|
||||
paramMap.put("payOrderId", payOrderId);
|
||||
String jsonParam = RpcUtil.createBaseParam(paramMap);
|
||||
result = rpcCommonService.rpcPayOrderService.selectPayOrderByMchIdAndPayOrderId(jsonParam);
|
||||
}else {
|
||||
paramMap.put("mchId", mchId);
|
||||
paramMap.put("mchOrderNo", mchOrderNo);
|
||||
String jsonParam = RpcUtil.createBaseParam(paramMap);
|
||||
result = rpcCommonService.rpcPayOrderService.selectPayOrderByMchIdAndPayOrderId(jsonParam);
|
||||
}
|
||||
String s = RpcUtil.mkRet(result);
|
||||
if(s == null) return null;
|
||||
boolean isNotify = Boolean.parseBoolean(executeNotify);
|
||||
JSONObject payOrder = JSONObject.parseObject(s);
|
||||
if(isNotify) {
|
||||
paramMap = new HashMap<>();
|
||||
paramMap.put("payOrderId", payOrderId);
|
||||
String jsonParam = RpcUtil.createBaseParam(paramMap);
|
||||
result = rpcCommonService.rpcNotifyPayService.sendBizPayNotify(jsonParam);
|
||||
s = RpcUtil.mkRet(result);
|
||||
_log.info("业务查单完成,并再次发送业务支付通知.发送结果:{}", s);
|
||||
}
|
||||
return payOrder;
|
||||
}
|
||||
|
||||
public String doWxPayReq(String tradeType, JSONObject payOrder, String resKey) {
|
||||
Map<String,Object> paramMap = new HashMap<>();
|
||||
paramMap.put("tradeType", tradeType);
|
||||
paramMap.put("payOrder", payOrder);
|
||||
String jsonParam = RpcUtil.createBaseParam(paramMap);
|
||||
Map<String, Object> result = rpcCommonService.rpcPayChannel4WxService.doWxPayReq(jsonParam);
|
||||
String s = RpcUtil.mkRet(result);
|
||||
if(s == null) {
|
||||
return XXPayUtil.makeRetData(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_FAIL, "0111", "调用微信支付失败"), resKey);
|
||||
}
|
||||
Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
|
||||
map.putAll((Map) result.get("bizResult"));
|
||||
return XXPayUtil.makeRetData(map, resKey);
|
||||
}
|
||||
|
||||
public String doAliPayReq(String channelId, JSONObject payOrder, String resKey) {
|
||||
Map<String,Object> paramMap = new HashMap<>();
|
||||
paramMap.put("payOrder", payOrder);
|
||||
String jsonParam = RpcUtil.createBaseParam(paramMap);
|
||||
Map<String, Object> result;
|
||||
switch (channelId) {
|
||||
case PayConstant.PAY_CHANNEL_ALIPAY_MOBILE :
|
||||
result = rpcCommonService.rpcPayChannel4AliService.doAliPayMobileReq(jsonParam);
|
||||
break;
|
||||
case PayConstant.PAY_CHANNEL_ALIPAY_PC :
|
||||
result = rpcCommonService.rpcPayChannel4AliService.doAliPayPcReq(jsonParam);
|
||||
break;
|
||||
case PayConstant.PAY_CHANNEL_ALIPAY_WAP :
|
||||
result = rpcCommonService.rpcPayChannel4AliService.doAliPayWapReq(jsonParam);
|
||||
break;
|
||||
case PayConstant.PAY_CHANNEL_ALIPAY_QR :
|
||||
result = rpcCommonService.rpcPayChannel4AliService.doAliPayQrReq(jsonParam);
|
||||
break;
|
||||
default:
|
||||
result = null;
|
||||
break;
|
||||
}
|
||||
String s = RpcUtil.mkRet(result);
|
||||
if(s == null) {
|
||||
return XXPayUtil.makeRetData(XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_FAIL, "0111", "调用支付宝支付失败"), resKey);
|
||||
}
|
||||
Map<String, Object> map = XXPayUtil.makeRetMap(PayConstant.RETURN_VALUE_SUCCESS, "", PayConstant.RETURN_VALUE_SUCCESS, null);
|
||||
map.putAll((Map) result.get("bizResult"));
|
||||
return XXPayUtil.makeRetData(map, resKey);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,33 @@
|
|||
package org.xxpay.dubbo.web.service;
|
||||
|
||||
import com.alibaba.dubbo.config.annotation.Reference;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.xxpay.dubbo.api.service.*;
|
||||
|
||||
/**
|
||||
* @author: dingzhiwei
|
||||
* @date: 17/9/10
|
||||
* @description:
|
||||
*/
|
||||
@Service
|
||||
public class RpcCommonService {
|
||||
|
||||
@Reference(version = "1.0.0", timeout = 10000, retries = 0)
|
||||
public IMchInfoService rpcMchInfoService;
|
||||
|
||||
@Reference(version = "1.0.0", timeout = 10000, retries = 0)
|
||||
public IPayChannelService rpcPayChannelService;
|
||||
|
||||
@Reference(version = "1.0.0", timeout = 10000, retries = 0)
|
||||
public IPayOrderService rpcPayOrderService;
|
||||
|
||||
@Reference(version = "1.0.0", timeout = 10000, retries = 0)
|
||||
public IPayChannel4WxService rpcPayChannel4WxService;
|
||||
|
||||
@Reference(version = "1.0.0", timeout = 10000, retries = 0)
|
||||
public IPayChannel4AliService rpcPayChannel4AliService;
|
||||
|
||||
@Reference(version = "1.0.0", timeout = 10000, retries = 0)
|
||||
public INotifyPayService rpcNotifyPayService;
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,10 @@
|
|||
server:
|
||||
port: 3020
|
||||
|
||||
spring:
|
||||
dubbo:
|
||||
application:
|
||||
name: xxpay4dubbo-web
|
||||
registry:
|
||||
address: zookeeper://127.0.0.1:2181
|
||||
scan: org.xxpay.dubbo
|
||||
|
|
@ -76,7 +76,7 @@ public class Notify4WxPayController extends Notify4BasePay {
|
|||
WxPayConfig wxPayConfig = (WxPayConfig) payContext.get("wxPayConfig");
|
||||
wxPayService.setConfig(wxPayConfig);
|
||||
// 这里做了签名校验(这里又做了一次xml转换对象,可以考虑优化)
|
||||
wxPayService.getOrderNotifyResult(xmlResult);
|
||||
wxPayService.parseOrderNotifyResult(xmlResult);
|
||||
// 处理订单
|
||||
byte payStatus = payOrder.getStatus(); // 0:订单生成,1:支付中,-1:支付失败,2:支付成功,3:业务处理完成,-2:订单过期
|
||||
if (payStatus != PayConstant.PAY_STATUS_SUCCESS && payStatus != PayConstant.PAY_STATUS_COMPLETE) {
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ import com.alibaba.fastjson.JSONObject;
|
|||
import com.github.binarywang.wxpay.bean.request.WxPayUnifiedOrderRequest;
|
||||
import com.github.binarywang.wxpay.bean.result.WxPayUnifiedOrderResult;
|
||||
import com.github.binarywang.wxpay.config.WxPayConfig;
|
||||
import com.github.binarywang.wxpay.constant.WxPayConstants;
|
||||
import com.github.binarywang.wxpay.exception.WxPayException;
|
||||
import com.github.binarywang.wxpay.service.WxPayService;
|
||||
import com.github.binarywang.wxpay.service.impl.WxPayServiceImpl;
|
||||
|
|
@ -93,11 +94,44 @@ public class PayChannel4WxController{
|
|||
break;
|
||||
}
|
||||
case PayConstant.WxConstant.TRADE_TYPE_APP : {
|
||||
map.put("payParams", wxPayService.getPayInfo(wxPayUnifiedOrderRequest));
|
||||
Map<String, String> payInfo = new HashMap<>();
|
||||
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
String nonceStr = String.valueOf(System.currentTimeMillis());
|
||||
// APP支付绑定的是微信开放平台上的账号,APPID为开放平台上绑定APP后发放的参数
|
||||
String appId = wxPayConfig.getAppId();
|
||||
Map<String, String> configMap = new HashMap<>();
|
||||
// 此map用于参与调起sdk支付的二次签名,格式全小写,timestamp只能是10位,格式固定,切勿修改
|
||||
String partnerId = wxPayConfig.getMchId();
|
||||
configMap.put("prepayid", wxPayUnifiedOrderResult.getPrepayId());
|
||||
configMap.put("partnerid", partnerId);
|
||||
String packageValue = "Sign=WXPay";
|
||||
configMap.put("package", packageValue);
|
||||
configMap.put("timestamp", timestamp);
|
||||
configMap.put("noncestr", nonceStr);
|
||||
configMap.put("appid", appId);
|
||||
// 此map用于客户端与微信服务器交互
|
||||
payInfo.put("sign", SignUtils.createSign(configMap, wxPayConfig.getMchKey(), null));
|
||||
payInfo.put("prepayId", wxPayUnifiedOrderResult.getPrepayId());
|
||||
payInfo.put("partnerId", partnerId);
|
||||
payInfo.put("appId", appId);
|
||||
payInfo.put("packageValue", packageValue);
|
||||
payInfo.put("timeStamp", timestamp);
|
||||
payInfo.put("nonceStr", nonceStr);
|
||||
map.put("payParams", payInfo);
|
||||
break;
|
||||
}
|
||||
case PayConstant.WxConstant.TRADE_TYPE_JSPAI : {
|
||||
map.put("payParams", wxPayService.getPayInfo(wxPayUnifiedOrderRequest));
|
||||
Map<String, String> payInfo = new HashMap<>();
|
||||
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
|
||||
String nonceStr = String.valueOf(System.currentTimeMillis());
|
||||
payInfo.put("appId", wxPayUnifiedOrderResult.getAppid());
|
||||
// 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
|
||||
payInfo.put("timeStamp", timestamp);
|
||||
payInfo.put("nonceStr", nonceStr);
|
||||
payInfo.put("package", "prepay_id=" + wxPayUnifiedOrderResult.getPrepayId());
|
||||
payInfo.put("signType", WxPayConstants.SignType.MD5);
|
||||
payInfo.put("paySign", SignUtils.createSign(payInfo, wxPayConfig.getMchKey(), null));
|
||||
map.put("payParams", payInfo);
|
||||
break;
|
||||
}
|
||||
case PayConstant.WxConstant.TRADE_TYPE_MWEB : {
|
||||
|
|
|
|||
Loading…
Reference in New Issue