Authored by LUOXC

refactor

Showing 23 changed files with 242 additions and 625 deletions
... ... @@ -23,28 +23,36 @@ public class WXUtils {
/**
* 生成Md5签名(新版本API)
* @param Map<String, String> 参数对
* @param String 商户私钥
* @return String
*/
public static String signMd5(Map<String, String> paramMap, String privateKey){
if(null == paramMap){
return "";
}
Map<String, String> sortMap = getSortedSignMap(paramMap);
StringBuilder strBuilder = new StringBuilder();
for(Map.Entry<String, String> entry : sortMap.entrySet()){
strBuilder.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
}
StringBuilder strBuilder = buildPreSignContent(paramMap);
//字典排序后再拼接上商户密钥
strBuilder.append("key").append("=").append(privateKey);
strBuilder.append("&").append("key").append("=").append(privateKey);
String md5Sign = MD5Utils.signMd5(strBuilder.toString(), "UTF-8").toUpperCase();
return md5Sign;
}
public static StringBuilder buildPreSignContent(Map<String, String> paramMap) {
Map<String, String> sortMap = getSortedSignMap(paramMap);
StringBuilder strBuilder = new StringBuilder();
boolean isFirst = true;
for (Map.Entry<String, String> entry : sortMap.entrySet()) {
if (isFirst) {
isFirst = false;
} else {
strBuilder.append("&");
}
strBuilder.append(entry.getKey()).append("=").append(entry.getValue());
}
return strBuilder;
}
private static Map<String, String> getSortedSignMap(Map<String, String> paramMap) {
//使用SortedMap将参数按名称的字典序排队
SortedMap<String, String> sortMap = new TreeMap<String, String>();
... ...
... ... @@ -17,6 +17,10 @@
<groupId>com.yohoufo.fore</groupId>
<artifactId>yohoufo-fore-common</artifactId>
</dependency>
<dependency>
<groupId>com.yoho.core</groupId>
<artifactId>security</artifactId>
</dependency>
<dependency>
<groupId>com.yohoufo.fore</groupId>
... ...
... ... @@ -8,115 +8,18 @@ public class WeixinPayConfig {
public static final String TRADE_TYPE_NATIVE = "NATIVE"; //原生扫码支付
public static final String TRADE_TYPE_JSAPI = "JSAPI"; //小程序、H5支付
/**
* 商家可以考虑读取配置文件
*/
// {"app_id":"wx049fdaa3ba9cdd7a",
// "app_secret":"f973fdb412307ea7b97d0252fd675104",
// "partner_key":"b22de5cfd0ded341e0516505f72649a9",
// "pay_sign_key":"wGwAsgU5SeeM62glYaoC6ALBKhtOrF7Ek9LzE8trEuUG7jHeFdnSlyA1jblOYYS57QzWr8dYVsWGdeWhzeonnrKFZakgwFWPYVtyeP4XqSu9Qvxps8LEgxoFBEpRPm6C",
// "partner_id":1218934901}
/**微信商户号1,当前微信APP支付、H5使用这个商户号**/
public static final String APP_ID = "wx049fdaa3ba9cdd7a"; // "wxd930ea5d5a258f4f";//微信开发平台应用id
public static final String APP_SECRET = "f973fdb412307ea7b97d0252fd675104"; //"db426a9829e4b49a0dcac7b4162da6b6";//应用对应的凭证
//应用对应的密钥
public static final String APP_KEY = "wGwAsgU5SeeM62glYaoC6ALBKhtOrF7Ek9LzE8trEuUG7jHeFdnSlyA1jblOYYS57QzWr8dYVsWGdeWhzeonnrKFZakgwFWPYVtyeP4XqSu9Qvxps8LEgxoFBEpRPm6C"; // "L8LrMqqeGRxST5reouB0K66CaYAWpqhAVsq7ggKkxHCOastWksvuX1uvmvQclxaHoYd3ElNBrNO2DHnnzgfVG9Qs473M3DTOZug5er46FhuGofumV8H2FVR9qkjSlC5K";
public static final String PARTNER = "1218934901"; // "1900000109";//财付通商户号
public static final String PARTNER_KEY = "b22de5cfd0ded341e0516505f72649a9"; // "8934e7d15453e97507ef794cf7b0519d";//商户号对应的密钥
public static final String TOKENURL = "https://api.weixin.qq.com/cgi-bin/token";//获取access_token对应的url
public static final String GRANT_TYPE = "client_credential";//常量固定值
public static final String EXPIRE_ERRCODE = "42001";//access_token失效后请求返回的errcode
public static final String FAIL_ERRCODE = "40001";//重复获取导致上一次获取的access_token失效,返回错误码
public static final String GATEURL = "https://api.weixin.qq.com/pay/genprepay?access_token=";//获取预支付id的接口url
public static final String ACCESS_TOKEN = "access_token";//access_token常量值
public static final String ERRORCODE = "errcode";//用来判断access_token是否失效的值
public static final String SIGN_METHOD = "sha1";//签名算法常量值
//package常量值
//public static String packageValue = "bank_type=WX&body=%B2%E2%CA%D4&fee_type=1&input_charset=GBK&notify_url=http%3A%2F%2F127.0.0.1%3A8180%2Ftenpay_api_b2c%2FpayNotifyUrl.jsp&out_trade_no=2051571832&partner=1900000109&sign=10DA99BCB3F63EF23E4981B331B0A3EF&spbill_create_ip=127.0.0.1&time_expire=20131222091010&total_fee=1";
public static final String packageValue = "bank_type=WX&body=%E8%AE%A2%E5%8D%95%E5%8F%B7%3A1619199705&fee_type=1&input_charset=UTF-8&notify_url=http%3A%2F%2Fdevservice.yoho.cn%3A58077%2Fpayment%2Fwechat_notify&out_trade_no=YOHOBuy_1619199705&partner=1218934901&sign=1E967995AA1F2E5DB5B03969ADEA2FA0&spbill_create_ip=172.16.8.137&time_expire=20160121181546&total_fee=239900";
public static final String traceid = "testtraceid001";//测试用户id
//证书
public static final String WECHAT_PAY_APP_PARTNER_CERT = "/certs/wechatpay/apiclient_cert_app.p12";
/**微信商户号2,当前微信扫码使用这个商户号**/
public static final String APP_ID_2 = "wx75e5a7c0c88e45c2";
public static final String APP_SECRET_2 = "b97db82a751c77a1328a448f639eb3b0";
public static final String PARTNER_2 = "1227694201";
public static final String PARTNER_KEY_2 = "7e6f3307b64cc87c79c472814b88f7fb";
public static final String WECHAT_PAY_PCWAP_PARTNER_CERT = "/certs/wechatpay/apiclient_cert_web.p12";
/**微信支付BLK商户号**/
public static final String APP_ID_BLK = "wxa43b93a3b0b561b2";
public static final String APP_SECRET_BLK = "ce21ae4a3f93852279175a167e54509b";
public static final String PARTNER_BLK_APP = "1370681002";
public static final String PARTNER_KEY_BLK_APP = "2c938242a60d98c2f494ce0a71819974";
public static final String WECHAT_PAY_BLKAPP_PARTNER_CERT = "/certs/wechatpay/apiclient_cert_blk_app.p12";
/**微信支付UFO商户号**/
public static final String APP_ID_UFO = "wxa789c1da9516020f";
public static final String APP_SECRET_UFO = "";
public static final String PARTNER_UFO_APP = "1515489021";
public static final String PARTNER_KEY_UFO_APP = "ad64b940159d0ada893d0df5de715daa";
public static final String WECHAT_PAY_UFOAPP_PARTNER_CERT = "/certs/wechatpay/apiclient_cert_ufo_app.p12";
/**微信支付UFO商户号正式**/
public static final String APP_ID_UFO_REAL = "wx75b18b98bdd92bbc";
public static final String APP_SECRET_UFO_REAL = "";
public static final String PARTNER_UFO_REAL_APP = "1516774631";
public static final String PARTNER_KEY_UFO_REAL_APP = "5f47f0050f5550f16d9262c65a165e0f";
public static final String WECHAT_PAY_UFOREAL_APP_PARTNER_CERT = "/certs/wechatpay/apiclient_cert_ufo_real_app.p12";
public interface Miniapp{
String APP_PARTNER_CERT = "/certs/wechatpay/apiclient_cert_wx_miniapp.p12";
String KEY = PARTNER_KEY_UFO_REAL_APP;
String APPID = "wxc677c88385762287";
String MALL_ID = PARTNER_UFO_REAL_APP;
}
public static final String APP_ID_BLK_PC = "wxd370556ef064789e";
public static final String APP_SECRET_BLK_PC = "xxxxxxxxxxxxxxxxxxxx";
public static final String PARTNER_BLK_PC = "1374750202";
public static final String PARTNER_KEY_BLK_PC = "a13171560afd63e7dcf76ed1d08c2929";
public static final String WECHAT_PAY_BLKPC_PARTNER_CERT = "/certs/wechatpay/apiclient_cert_blk_pc.p12";
public static final String APP_ID_OUYIN = "wxa0d65505ae5e0860";
public static final String APP_SECRET_OUYIN = "xxxxxxxxxxxxxxxxxxxx";
public static final String PARTNER_OUYIN = "1392759102";
public static final String PARTNER_KEY_OUYIN = "f70a95654c5d0400d75f0e72602da7ad";
public static final String OUYIN_PARTNER_CERT = "/certs/wechatpay/apiclient_cert_ouyin.p12";
//欧印南京第一分公司
public static final String APP_ID_OUYIN01 = "wxb721666873174aca";
public static final String APP_SECRET_OUYIN01 = "xxxxxxxxxxxxxxxxxxxx";
public static final String PARTNER_OUYIN01 = "1494640762";
public static final String PARTNER_KEY_OUYIN01 = "6c5fd994d4163f99dcc09843ae12e1eb";
public static final String OUYIN01_PARTNER_CERT = "/certs/wechatpay/apiclient_cert_ouyin01.p12";
/**
* 小程序的APPID
* 小程序的支付绑定到BLK账号:1370681002
*/
public static final String APP_ID_MINIAPP = "wx084ab813d88c594b";
/**
* 有货商品精选小程序
* 支付同样绑定到BLK支付账号:1370681002
*/
public static final String APP_ID_MINIAPP_MALL = "wxe4f1cbdfd470035d";
public static final String PARTNER_MINIAPP_MALL = "1483488462";
public static final String PARTNER_KEY_MINIAPP_MALL = "86dcd67211bfe36fda75200cbc32a748";
public static final String PARTNER_CERT_MINIAPP_MALL = "/certs/wechatpay/apiclient_cert_miniapp_mall.p12";
// private static final Map<String, String> MCH_KEY_MAP = new HashMap<String, String>();
// static {
// MCH_KEY_MAP.put(PARTNER, PARTNER_KEY);
// MCH_KEY_MAP.put(PARTNER_2, PARTNER_KEY_2);
// }
//查询微信支付订单前缀
public static final String WECHAT_TRADE_NO_PREFIX = "YOHOBuy_";
... ... @@ -127,20 +30,8 @@ public class WeixinPayConfig {
public static final String WEIXIN_PAY_REFUND_URL = "https://api.mch.weixin.qq.com/secapi/pay/refund";
public static final String WEIXIN_PAY_CLOSEORDER_URL = "https://api.mch.weixin.qq.com/pay/closeorder";
public static final String WEIXIN_PAY_BARCODE_URL = "https://api.mch.weixin.qq.com/pay/micropay";
public static final String WEIXIN_PAY_BARCODE_REVERT_URL = "https://api.mch.weixin.qq.com/secapi/pay/reverse";
//微信支付新API相关常量定义
public class ApiConstants{
//微信预支付URL(新API)
public static final String WEIXIN_PREPAY_URL = "https://api.mch.weixin.qq.com/pay/unifiedorder";
//用于签名的商户密钥字段名
public static final String KEY = "key";
public static final String DEFAULT_CHARACTER_SET = "UTF-8";
//-------统一下单接口字段----------------------------------------
//应用ID
... ... @@ -198,14 +89,6 @@ public class WeixinPayConfig {
public static final String PREPAY_RESULT_FAIL = "FAIL";
}
/**
* 根据商户号返回key
* @param mchId
* @return
*/
// public static String getMchKey(String mchId) {
// return MCH_KEY_MAP.get(mchId);
// }
... ...
... ... @@ -9,9 +9,8 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.yohoufo.order.service.pay.alipay.AlipayCrossBorderService;
import com.yohoufo.order.service.pay.alipay.AlipayServiceAbstract;
import com.yohoufo.order.service.pay.alipay.AbstractAlipayService;
import com.yohoufo.order.service.pay.unionpay.JsUnionpayService;
import net.sf.oval.constraint.AssertURL;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -22,7 +21,6 @@ import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.req.ManualDealRequest;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.common.annotation.IgnoreSession;
... ... @@ -250,7 +248,7 @@ public class PaymentController {
return ;
}
AlipayServiceAbstract alipayServiceAbstract;
AbstractAlipayService alipayServiceAbstract;
// 跨境支付宝的回调
if (params.containsKey("currency")){
... ...
... ... @@ -6,9 +6,13 @@ import com.google.common.base.Splitter;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohobuy.ufo.model.order.bo.OutTradeNoMeta;
import com.yohobuy.ufo.model.order.common.Payment;
import com.yohobuy.ufo.model.user.resp.AuthorizeResultRespVO;
import com.yohoufo.common.utils.*;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.common.utils.HttpClient;
import com.yohoufo.common.utils.RSAUtils;
import com.yohoufo.common.utils.WXUtil;
import com.yohoufo.dal.order.OrdersPayHbfqMapper;
import com.yohoufo.dal.order.model.OrdersPayHbfq;
import com.yohoufo.order.common.HbfqEnum;
... ... @@ -20,7 +24,6 @@ import com.yohoufo.order.model.PaymentData;
import com.yohoufo.order.model.TransferData;
import com.yohoufo.order.service.PaymentSupportService;
import com.yohoufo.order.service.pay.AbstractPayService;
import com.yohobuy.ufo.model.order.bo.OutTradeNoMeta;
import com.yohoufo.order.service.support.codegenerator.OrderCodeGenerator;
import com.yohoufo.order.service.transfer.TransferChannel;
import com.yohoufo.order.service.transfer.TransferResult;
... ... @@ -39,7 +42,7 @@ import java.text.SimpleDateFormat;
import java.util.*;
import java.util.function.BiConsumer;
public abstract class AlipayServiceAbstract extends AbstractPayService {
public abstract class AbstractAlipayService extends AbstractPayService {
private static final Logger logger = LoggerFactory.getLogger("alipayLogger");
... ... @@ -47,15 +50,23 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
@Autowired
private HttpClient httpClient;
protected abstract String getMd5Key();
protected abstract AlipaySignatureSetting getAlipaySignatureSetting();
protected abstract String getRsaAlipubKey();
protected final AlipaySignatureHelper helper() {
return factory.newAlipaySignatureHelper(getAlipaySignatureSetting());
}
protected abstract String getRsaPrivateKey();
private final String getAppId() {
return getAlipaySignatureSetting().getAppId();
}
protected abstract String getAppId();
protected final String getPartnerId() {
return getAlipaySignatureSetting().getPartnerId();
}
protected abstract String getPartnerId();
private final String getAlipaySignType() {
return getAlipaySignatureSetting().getRsaType();
}
protected String getAccountUserName() {
return "";
... ... @@ -70,6 +81,9 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
}
@Autowired
private AlipaySignatureHelperFactory factory;
@Autowired
PaymentSupportService paymentSupportService;
... ... @@ -93,33 +107,6 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
return notifyURL;
}
// public JSONObject prepayRequest(OrderInfo orderInfo){
//
// String tradeNo = String.valueOf(orderInfo.getOrderCode());
// String subject = "有货订单-" + tradeNo;
//
// AliMobliePayInfoBuilder builder = new AliMobliePayInfoBuilder();
// builder.addParam("service", "mobile.securitypay.pay")
// .addParam("partner", this.getPartnerId())
// .addParam("_input_charset", AlipayConfig.input_charset)
// .addParam("notify_url", notifyURL)
// //.addParam("out_trade_no", tradeNo)
// .addParam("subject", subject)
// .addParam("payment_type", "1") //固定位1,表示商品购买
// .addParam("seller_id", this.getPartnerId())
// .addParam("total_fee", orderInfo.getAmount().toPlainString())
// .addParam("body", subject);
//// .addParam("it_b_pay", orderInfo.getPayExpireTimeStr(Payment.ALIPAY));
//
// builder.addParam("out_trade_no", tradeNo);
//
// JSONObject jsonObject = new JSONObject();
// jsonObject.put("payParams", builder.buildSign());
//
// return jsonObject;
// }
public PayQueryBo payQuery(String tradeNo, int orderCreateTime) {
Map<String, String> queryParams = buildOpenApiQueryParams(tradeNo);
String respTxt = sendOpenApiRequest(tradeNo, queryParams, AlipayConfig.OPENAPI_URL);
... ... @@ -499,7 +486,6 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
/**
* openapi支付查询
* @param orderData
* @return
*/
private Map<String, String> buildOpenApiQueryParams(String orderCode) {
... ... @@ -516,13 +502,12 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
params.put("biz_content", bizJson.toJSONString());
String preSignStr = getOpenApiSignString(params,false);
params.put("sign", RSAUtils.sign(preSignStr, getRsaPrivateKey(), AlipayConfig.input_charset));
params.put("sign", helper().signWithRsa(preSignStr,AlipayConfig.input_charset));
return params;
}
/**
* openapi支付查询
* @param orderData
* @return
*/
private Map<String, String> buildAlipayTransferQueryParams(String orderCode) {
... ... @@ -539,14 +524,13 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
params.put("biz_content", bizJson.toJSONString());
String preSignStr = getOpenApiSignString(params, false);
params.put("sign", RSAUtils.sign(preSignStr, getRsaPrivateKey(), AlipayConfig.input_charset));
params.put("sign", helper().signWithRsa(preSignStr,AlipayConfig.input_charset));
return params;
}
/**
* 单笔转账
* @param orderData
* @return
*/
private Map<String, String> buildTransferParams(String transferOrderCode, String alipayUid, String alipayAccount, BigDecimal transferAmount) {
... ... @@ -574,13 +558,12 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
params.put("biz_content", bizJson.toJSONString());
String preSignStr = getOpenApiSignString(params, false);
params.put("sign", RSAUtils.sign(preSignStr, getRsaPrivateKey(), AlipayConfig.input_charset));
params.put("sign", helper().signWithRsa(preSignStr,AlipayConfig.input_charset));
return params;
}
/**
* 单笔转账
* @param orderData
* @return
*/
private Map<String, String> buildTransferParamsWhenExceedMillion(String transferOrderCode, String businessId, String alipayUid, String alipayAccount, String userName, BigDecimal transferAmount) {
... ... @@ -611,7 +594,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
params.put("detail_data", detailAppender.toString());
String preSignStr = getOpenApiSignString(params, false);
params.put("sign", RSAUtils.sign(preSignStr, getRsaPrivateKey(), AlipayConfig.input_charset));
params.put("sign", helper().signWithRsa(preSignStr,AlipayConfig.input_charset));
params.put("sign_type", "RSA");
return params;
}
... ... @@ -672,7 +655,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
params.put("biz_content", bizJson.toJSONString());
String preSignStr = getOpenApiSignString(params, false);
String sign = RSAUtils.sign(preSignStr, getRsaPrivateKey(), AlipayConfig.input_charset);
String sign = helper().signWithRsa(preSignStr,AlipayConfig.input_charset);
params.put("sign", URLEncoder.encode(sign));
// 对biz_content进行encode
... ... @@ -685,7 +668,6 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
/**
* 花呗分期payOrderCode记录
* @param hbfqRecord
* @return
*/
public boolean recordOrdersPayHbfq(String outTradeNo, String tradeNo, int uid) {
... ... @@ -842,7 +824,6 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
/**
* 将xml转换为对象
*
* @param xml
* @return
*/
public PayRefundBo refundOpenApiConvert(String respText, PayRefundBo bo) {
... ... @@ -906,7 +887,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
params.put("biz_content", bizJson.toJSONString());
String preSignStr = getOpenApiSignString(params, false);
params.put("sign", RSAUtils.sign(preSignStr, getRsaPrivateKey(), AlipayConfig.input_charset));
params.put("sign", helper().signWithRsa(preSignStr,AlipayConfig.input_charset));
return params;
}
... ... @@ -919,7 +900,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
*/
public String rsaSign(Map<String, String> paramsMap) {
String preSignStr = getSignString(paramsMap);
return RSAUtils.sign(preSignStr, getRsaPrivateKey(), AlipayConfig.input_charset);
return helper().signWithRsa(preSignStr,AlipayConfig.input_charset);
}
/**
* 生成RSA签名
... ... @@ -927,7 +908,7 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
* @return
*/
public String rsaSign(String preSignStr) {
return RSAUtils.sign(preSignStr, getRsaPrivateKey(), AlipayConfig.input_charset);
return helper().signWithRsa(preSignStr,AlipayConfig.input_charset);
}
/**
... ... @@ -936,17 +917,16 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
* @return
*/
public boolean signVerify(Map<String, String> paramsMap) {
if(null == paramsMap) {
if (null == paramsMap) {
return false;
}
boolean result = false;
String signType = paramsMap.get("sign_type");
if("RSA".equals(signType)) {
if ("RSA".equals(signType)) {
result = rsaSignVerify(paramsMap);
}
else if ("MD5".equals(signType)) {
result = md5SignVerify(paramsMap);
} else {
logger.warn("[{}] notification sign check: not support sign type {}", paramsMap.get("out_trade_no"), signType);
}
logger.info("[{}] notification sign check: {}", paramsMap.get("out_trade_no"), result);
return result;
... ... @@ -989,33 +969,13 @@ public abstract class AlipayServiceAbstract extends AbstractPayService {
}
/**
* 验证MD5签名
* @param paramsMap
* @return
*/
public boolean md5SignVerify(Map<String, String> paramsMap) {
String preSignStr = getSignString(paramsMap) + getMd5Key();
String sign = MD5Utils.signMd5(preSignStr, AlipayConfig.input_charset);
if(null != sign && sign.equals(paramsMap.get("sign"))) {
return true;
}
return false;
}
/**
* 验证RSA签名
* @param paramsMap
* @return
*/
public boolean rsaSignVerify(Map<String, String> paramsMap) {
String preSignStr = getSignString(paramsMap);
logger.info("method rsaSignVerify in preSignStr is {}, sign is {}, RsaAlipubKey is {}", preSignStr, paramsMap.get("sign"), getRsaAlipubKey());
return RSAUtils.verify(preSignStr, paramsMap.get("sign"), getRsaAlipubKey(), AlipayConfig.input_charset);
return helper().verifyWithRsa(preSignStr,AlipayConfig.input_charset,paramsMap.get("sign"));
}
/**
... ...
package com.yohoufo.order.service.pay.alipay;
import com.yohoufo.order.config.AlipayConfig;
import org.springframework.stereotype.Service;
@Service
public class AlipayBlkService extends AlipayServiceAbstract {
@Override
protected String getPartnerId() {
return AlipayConfig.BLK_PARTNER;
}
@Override
protected String getMd5Key() {
return AlipayConfig.BLK_KEY_MD5;
}
@Override
protected String getRsaPrivateKey() {
return AlipayConfig.BLK_MCH_RSA_PRIVATE;
}
@Override
protected String getRsaAlipubKey() {
return AlipayConfig.BLK_ALI_RSA_PUBLIC;
}
@Override
protected String getAppId() {
return AlipayConfig.BLK_APPID;
}
}
package com.yohoufo.order.service.pay.alipay;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.yohobuy.ufo.model.order.bo.OrderInfo;
import com.yohoufo.common.utils.DateUtil;
... ... @@ -12,47 +11,27 @@ import com.yohoufo.order.model.PayQueryBo;
import com.yohoufo.order.model.PayRefundBo;
import com.yohoufo.order.service.pay.alipay.bean.AlipayQueryResponse;
import com.yohoufo.order.service.pay.alipay.bean.AlipayRefundResponse;
import org.apache.commons.lang3.StringUtils;
import org.apache.http.client.utils.DateUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Service
public class AlipayCrossBorderService extends AlipayServiceAbstract {
public class AlipayCrossBorderService extends AbstractAlipayService {
private static final Logger logger = LoggerFactory.getLogger("alipayLogger");
@Override
protected String getMd5Key() {
return "";
}
@Override
protected String getRsaAlipubKey() {
return AlipayConfig.CROSS_BORDER_RSA_PUBLIC;
}
@Override
protected String getRsaPrivateKey() {
return AlipayConfig.CROSS_BORDER_RSA_PRIVATE;
}
@Override
protected String getAppId() {
return "";
}
@Override
protected String getPartnerId() {
return "2088121119526910";
protected AlipaySignatureSetting getAlipaySignatureSetting() {
return new AlipaySignatureSetting(
"2088121119526910",
"2088121119526910",
false,
"RSA"
);
}
private String getSellerId(){
... ... @@ -114,7 +93,7 @@ public class AlipayCrossBorderService extends AlipayServiceAbstract {
params.put("product_code", "NEW_WAP_OVERSEAS_SELLER");
String preSignStr = getOpenApiSignString(params, true);
params.put("sign", RSAUtils.sign(preSignStr, getRsaPrivateKey(), AlipayConfig.input_charset));
params.put("sign", helper().signWithRsa(preSignStr,AlipayConfig.input_charset));
return params;
}
... ... @@ -160,7 +139,7 @@ public class AlipayCrossBorderService extends AlipayServiceAbstract {
params.put("out_trade_no", orderCode);
String preSignStr = getOpenApiSignString(params, true);
params.put("sign", RSAUtils.sign(preSignStr, getRsaPrivateKey(), AlipayConfig.input_charset));
params.put("sign", helper().signWithRsa(preSignStr,AlipayConfig.input_charset));
return params;
}
... ... @@ -227,7 +206,7 @@ public class AlipayCrossBorderService extends AlipayServiceAbstract {
params.put("trade_information", trade_information.toJSONString());
String preSignStr = getOpenApiSignString(params, true);
String sign = RSAUtils.sign(preSignStr, getRsaPrivateKey(), AlipayConfig.input_charset);
String sign = helper().signWithRsa(preSignStr,AlipayConfig.input_charset);
params.put("sign", URLEncoder.encode(sign));
return params;
... ...
package com.yohoufo.order.service.pay.alipay;
import com.yohoufo.order.config.AlipayConfig;
import org.springframework.stereotype.Service;
@Service
public class AlipayOuyin01Service extends AlipayServiceAbstract {
@Override
protected String getPartnerId() {
return AlipayConfig.OUYIN01_PARTNER;
}
@Override
protected String getMd5Key() {
return AlipayConfig.OUYIN01_KEY_MD5;
}
@Override
protected String getRsaPrivateKey() {
return AlipayConfig.OUYIN01_MCH_RSA_PRIVATE;
}
@Override
protected String getRsaAlipubKey() {
return AlipayConfig.OUYIN01_ALI_RSA_PUBLIC;
}
@Override
protected String getAppId() {
return AlipayConfig.OUYIN01_APPID;
}
}
... ... @@ -2,36 +2,19 @@ package com.yohoufo.order.service.pay.alipay;
import com.yohoufo.order.config.AlipayConfig;
import java.util.Map;
import org.springframework.stereotype.Service;
@Service
public class AlipayOuyinService extends AlipayServiceAbstract {
@Override
protected String getPartnerId() {
return AlipayConfig.OUYIN_PARTNER;
}
@Override
protected String getMd5Key() {
return AlipayConfig.OUYIN_KEY_MD5;
}
@Override
protected String getRsaPrivateKey() {
return AlipayConfig.OUYIN_MCH_RSA_PRIVATE;
}
@Override
protected String getRsaAlipubKey() {
return AlipayConfig.OUYIN_ALI_RSA_PUBLIC;
}
public class AlipayOuyinService extends AbstractAlipayService {
@Override
protected String getAppId() {
return AlipayConfig.OUYIN_APPID;
protected AlipaySignatureSetting getAlipaySignatureSetting() {
return new AlipaySignatureSetting(
AlipayConfig.OUYIN_APPID,
AlipayConfig.OUYIN_PARTNER,
false,
"RSA"
);
}
@Override
... ...
package com.yohoufo.order.service.pay.alipay;
import com.yohoufo.order.config.AlipayConfig;
import org.springframework.stereotype.Service;
@Service
public class AlipayService extends AlipayServiceAbstract {
@Override
protected String getPartnerId() {
return AlipayConfig.partner;
}
@Override
protected String getMd5Key() {
return AlipayConfig.private_key_md5;
}
@Override
protected String getRsaPrivateKey() {
return AlipayConfig.private_key;
}
@Override
protected String getRsaAlipubKey() {
return AlipayConfig.ali_public_key;
}
@Override
protected String getAppId() {
return AlipayConfig.appid;
}
}
package com.yohoufo.order.service.pay.alipay;
import com.yoho.core.security.AlipayException;
import com.yoho.core.security.AlipayMapiHelper;
import com.yoho.core.security.AlipayOpenapiHelper;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import static com.yohoufo.order.utils.ServiceExceptions.throwServiceException;
@Slf4j
public class AlipaySignatureHelper {
private final AlipaySignatureSetting setting;
private final AlipayMapiHelper alipayMapiHelper;
private final AlipayOpenapiHelper alipayOpenapiHelper;
AlipaySignatureHelper(AlipaySignatureSetting setting, AlipayMapiHelper alipayMapiHelper, AlipayOpenapiHelper alipayOpenapiHelper) {
this.setting = setting;
this.alipayMapiHelper = alipayMapiHelper;
this.alipayOpenapiHelper = alipayOpenapiHelper;
}
public String signWithMd5(String content) {
String sign = StringUtils.EMPTY;
try {
sign = alipayMapiHelper.signMD5(setting.getPartnerId(), content);
} catch (AlipayException e) {
throwSignatureException(e);
}
return sign;
}
public String signWithRsa(String content, String charset) {
String sign = StringUtils.EMPTY;
if (setting.isUseMapi()) {
try {
sign = alipayMapiHelper.signRSA(setting.getPartnerId(), content, charset);
} catch (AlipayException e) {
throwSignatureException(e);
}
} else {
try {
sign = alipayOpenapiHelper.sign(setting.getAppId(), content, charset, setting.getRsaType());
} catch (AlipayException e) {
throwSignatureException(e);
}
}
return sign;
}
public boolean verifyWithRsa(String content, String charset, String sign) {
boolean success = false;
try {
success = alipayOpenapiHelper.verify(setting.getAppId(), content, sign, charset, setting.getRsaType());
} catch (AlipayException e) {
throwSignatureException(e);
}
return success;
}
public void throwSignatureException(Exception e) {
log.info("sign fail", e);
throwServiceException("支付宝签名失败");
}
}
\ No newline at end of file
... ...
package com.yohoufo.order.service.pay.alipay;
import com.yoho.core.security.AlipayMapiHelper;
import com.yoho.core.security.AlipayOpenapiHelper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Slf4j
@Service
public class AlipaySignatureHelperFactory {
@Autowired
private AlipayMapiHelper alipayMapiHelper;
@Autowired
private AlipayOpenapiHelper alipayOpenapiHelper;
public AlipaySignatureHelper newAlipaySignatureHelper(AlipaySignatureSetting setting) {
return new AlipaySignatureHelper(setting, alipayMapiHelper, alipayOpenapiHelper);
}
}
... ...
package com.yohoufo.order.service.pay.alipay;
import lombok.Value;
import lombok.experimental.Accessors;
@Value
@Accessors(chain = true)
public class AlipaySignatureSetting {
private String appId;
private String partnerId;
private boolean useMapi;
private String rsaType;
}
... ...
... ... @@ -2,6 +2,8 @@ package com.yohoufo.order.service.pay.weixin;
import com.alibaba.fastjson.JSONObject;
import com.yoho.core.common.utils.YHMath;
import com.yoho.core.security.WechatException;
import com.yoho.core.security.WechatHelper;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohoufo.common.utils.DateUtil;
... ... @@ -27,10 +29,12 @@ import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import static com.yohoufo.order.utils.ServiceExceptions.throwServiceException;
public abstract class AbstractWeixinPayService extends AbstractPayService {
private static final Logger logger = LoggerFactory.getLogger("wechatLogger");
private static final Logger log = LoggerFactory.getLogger("wechatLogger");
@Value("${wechat.notifyurl}")
... ... @@ -43,14 +47,13 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
@Autowired
PaymentSupportService paymentSupportService;
protected abstract String getMchId();
@Autowired
private WechatHelper wechatHelper;
protected abstract String getMchKey();
protected abstract String getMchId();
protected abstract String getAppId();
protected abstract String getMchCertPath();
protected abstract String getTradeType();
protected abstract HttpClient getSslHttpClient();
... ... @@ -60,12 +63,12 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
//验证业务结果
String resultCode = paramsMap.get(WeixinPayConfig.ApiConstants.RETURN_RESULT_CODE);
if(!WeixinPayConfig.ApiConstants.PREPAY_RESULT_SUCCESS.equals(resultCode)){
logger.error("[{}] trade failed, resultCode: {}", paramsMap.get("out_trade_no"), resultCode);
log.error("[{}] trade failed, resultCode: {}", paramsMap.get("out_trade_no"), resultCode);
return false;
}
if(!md5SignVerify(paramsMap)) {
logger.error("[{}] sign verify failed", paramsMap.get("out_trade_no"));
log.error("[{}] sign verify failed", paramsMap.get("out_trade_no"));
return false;
}
... ... @@ -135,17 +138,17 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
* @return
*/
private String sendQueryRequest(String tradeNo, String requestXml) {
logger.info("WeixinQuerier request tradeNo: {}, request: {}", tradeNo, requestXml);
log.info("WeixinQuerier request tradeNo: {}, request: {}", tradeNo, requestXml);
String respXml = "";
try {
respXml = httpClient.post(WeixinPayConfig.WEIXIN_PAY_QUERY_URL, requestXml);
} catch (Exception e) {
logger.error("WeixinQuerier request failed, orderCode:{}, ex: {}", tradeNo, e.getMessage());
log.error("WeixinQuerier request failed, orderCode:{}, ex: {}", tradeNo, e.getMessage());
return respXml;
}
logger.info("WeixinQuerier response: {}", respXml);
log.info("WeixinQuerier response: {}", respXml);
return respXml;
}
... ... @@ -164,15 +167,29 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
paramMap.put("nonce_str", WXUtils.getNonceStr());
//md5签名
String sign = WXUtils.signMd5(paramMap, getMchKey());
String sign = signByMD5(paramMap);
paramMap.put(WeixinPayConfig.ApiConstants.SIGN, sign);
return paramMap;
}
protected String signByMD5(Map<String, String> signParams) {
String sign;
try {
sign = wechatHelper.signByMD5(getMchId(), WXUtils.buildPreSignContent(signParams).toString());
} catch (WechatException e) {
log.info("wechat sign fail", e);
throwServiceException("微信签名失败");
sign = StringUtils.EMPTY;
}
return sign;
}
public PaymentData getPaymentData(Map<String, String> paramsMap) {
PaymentData paymentData = new PaymentData();
logger.info("paramsMap is: {}", paramsMap);
log.info("paramsMap is: {}", paramsMap);
try {
/**
* 普通支付 out_trade_no就是订单号
... ... @@ -197,7 +214,7 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
paymentData.setAppId(paramsMap.get("appid"));
} catch (Exception e) {
logger.error("[{}] get payment data error: {}", paramsMap.get("out_trade_no"), e.getMessage());
log.error("[{}] get payment data error: {}", paramsMap.get("out_trade_no"), e.getMessage());
throw new ServiceException(ServiceError.ORDER_PAYMENT_IS_EMPTY);
}
return paymentData;
... ... @@ -242,49 +259,48 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
/**
* 退款请求
* @param orderCode
* @param requestXml
* @return
*/
private String sendRefundRequest(String tradeNo, String requestXml) {
logger.info("WeixinRefunder request tradeNo: {}, request: {}", tradeNo, requestXml);
log.info("WeixinRefunder request tradeNo: {}, request: {}", tradeNo, requestXml);
String respXml = "";
HttpClient httpClient = getSslHttpClient();
if(httpClient == null) {
logger.error("init weixin ssl httpclient faild, unable refund weixinpay");
log.error("init weixin ssl httpclient faild, unable refund weixinpay");
return respXml;
}
try {
respXml = httpClient.post(WeixinPayConfig.WEIXIN_PAY_REFUND_URL, requestXml);
} catch (Exception e) {
logger.error("WeixinRefunder request failed, orderCode:{}, ex: {}", tradeNo, e.getMessage());
log.error("WeixinRefunder request failed, orderCode:{}, ex: {}", tradeNo, e.getMessage());
}
logger.info("WeixinRefunder response: {}", respXml);
log.info("WeixinRefunder response: {}", respXml);
return respXml;
}
public JSONObject prepayRequest(OrderInfo orderInfo) {
logger.info("[{}] prepayRequest begin", orderInfo.getOrderCode());
log.info("[{}] prepayRequest begin", orderInfo.getOrderCode());
Map<String, String> requestParams = buildPrepayParams( orderInfo);
String requestXml = WXUtils.createWXPayXml(requestParams);
String respXml = sendPrepayRequest(orderInfo.getOrderCode(), requestXml);
if(StringUtils.isEmpty(respXml)) {
logger.error("[{}] prepayRequest failed", orderInfo.getOrderCode());
log.error("[{}] prepayRequest failed", orderInfo.getOrderCode());
return null;
}
Map<String, String> reponseMap = WXUtils.parseWXPayXml(respXml);
if(!checkPrepayResponse(orderInfo.getOrderCode(), reponseMap)) {
logger.error("[{}] valid prepay response failed", orderInfo.getOrderCode());
log.error("[{}] valid prepay response failed", orderInfo.getOrderCode());
return null;
}
JSONObject prepayJson = getPrepayData(requestParams, reponseMap);
logger.info("[{}] response prepayData: {}", orderInfo.getOrderCode(), prepayJson);
log.info("[{}] response prepayData: {}", orderInfo.getOrderCode(), prepayJson);
return prepayJson;
}
... ... @@ -304,7 +320,7 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
//签名
//md5签名
String sign = WXUtils.signMd5(paramMap, getMchKey());
String sign = signByMD5(paramMap);
paramMap.put(WeixinPayConfig.ApiConstants.SIGN, sign);
return paramMap;
... ... @@ -342,7 +358,7 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
private JSONObject getNativePrepayData(Map<String, String> requestParams, Map<String, String> responseParams) {
String codeUrl = responseParams.get(WeixinPayConfig.ApiConstants.RETURN_CODE_URL);
if(StringUtils.isEmpty(codeUrl)) {
logger.error("[{}] obtain codeUrl failed", requestParams.get(WeixinPayConfig.ApiConstants.OUT_TRADE_NO));
log.error("[{}] obtain codeUrl failed", requestParams.get(WeixinPayConfig.ApiConstants.OUT_TRADE_NO));
return null;
}
JSONObject sendData = new JSONObject();
... ... @@ -358,7 +374,7 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
private JSONObject getJSAPIPrepayData(Map<String, String> requestParams, Map<String, String> responseParams) {
String prepayId = responseParams.get(WeixinPayConfig.ApiConstants.RETURN_PREPAY_ID);
if(StringUtils.isEmpty(prepayId)) {
logger.error("[{}] obtain prepayId failed", requestParams.get(WeixinPayConfig.ApiConstants.OUT_TRADE_NO));
log.error("[{}] obtain prepayId failed", requestParams.get(WeixinPayConfig.ApiConstants.OUT_TRADE_NO));
return null;
}
... ... @@ -371,7 +387,7 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
signParams.put("timeStamp", timeStamp);
signParams.put("signType", "MD5");
String sign = WXUtils.signMd5(signParams, getMchKey());
String sign = signByMD5(signParams);
JSONObject prepayJson = new JSONObject();
prepayJson.put("timeStamp", signParams.get("timeStamp"));
... ... @@ -391,7 +407,7 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
private JSONObject getAppPrepayData(Map<String, String> requestParams, Map<String, String> responseParams) {
String prepayId = responseParams.get(WeixinPayConfig.ApiConstants.RETURN_PREPAY_ID);
if(StringUtils.isEmpty(prepayId)) {
logger.error("[{}] obtain prepayId failed", requestParams.get(WeixinPayConfig.ApiConstants.OUT_TRADE_NO));
log.error("[{}] obtain prepayId failed", requestParams.get(WeixinPayConfig.ApiConstants.OUT_TRADE_NO));
return null;
}
... ... @@ -405,7 +421,7 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
prePayData.put("noncestr", requestParams.get(WeixinPayConfig.ApiConstants.NONCE_STR));
prePayData.put("timestamp", timeStamp);
String sign = WXUtils.signMd5(prePayData, getMchKey());
String sign = signByMD5(prePayData);
prePayData.put("sign", sign);
JSONObject sendData = new JSONObject();
... ... @@ -413,7 +429,7 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
sendData.put("token", "xxxxx"); //实际上没用,为兼容APP,暂且保留
sendData.put("prePayData", prePayData);
//logger.info("[] weixin prepay data: {}", requestParams.get(WeixinPayConfig.ApiConstants.OUT_TRADE_NO), prePayData);
//log.info("[] weixin prepay data: {}", requestParams.get(WeixinPayConfig.ApiConstants.OUT_TRADE_NO), prePayData);
return sendData;
}
... ... @@ -426,25 +442,25 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
*/
private boolean checkPrepayResponse(long orderCode, Map<String, String> reponseMap) {
if(reponseMap == null || reponseMap.size() == 0) {
logger.error("[{}] Prepay response parse failed", orderCode);
log.error("[{}] Prepay response parse failed", orderCode);
return false;
}
String returnCode = reponseMap.get(WeixinPayConfig.ApiConstants.RETURN_CODE);
String resultCode = reponseMap.get(WeixinPayConfig.ApiConstants.RETURN_RESULT_CODE);
if(!WeixinPayConfig.ApiConstants.PREPAY_RESULT_SUCCESS.equals(returnCode)) {
logger.error("[{}] prepay returnCode error: {}", orderCode, returnCode);
log.error("[{}] prepay returnCode error: {}", orderCode, returnCode);
return false;
}
//验证签名
if(!md5SignVerify(reponseMap)){
logger.error("[{}] sign verify failed", orderCode);
log.error("[{}] sign verify failed", orderCode);
return false;
}
//return_code和result_code都为SUCCESS时,返回prepayId
if(!WeixinPayConfig.ApiConstants.PREPAY_RESULT_SUCCESS.equals(resultCode)){
logger.error("[{}] prepay resultCode error: {}", orderCode, resultCode);
log.error("[{}] prepay resultCode error: {}", orderCode, resultCode);
return false;
}
... ... @@ -461,8 +477,7 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
if(paramsMap == null)
return false;
return WXUtils.signMd5(paramsMap, getMchKey())
.equals(paramsMap.get(WeixinPayConfig.ApiConstants.SIGN));
return signByMD5(paramsMap).equals(paramsMap.get(WeixinPayConfig.ApiConstants.SIGN));
}
/**
... ... @@ -472,17 +487,17 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
* @return
*/
private String sendPrepayRequest(long orderCode, String requestXml) {
logger.info("[{}] prepay request: {}", orderCode, requestXml);
log.info("[{}] prepay request: {}", orderCode, requestXml);
String respXml = "";
try {
respXml = httpClient.post(WeixinPayConfig.WEIXIN_PREPAY_URL, requestXml);
} catch (Exception e) {
logger.error("[{}] prepay request failed: {}", orderCode, e.getMessage());
log.error("[{}] prepay request failed: {}", orderCode, e.getMessage());
return respXml;
}
logger.info("[{}] prepay response: {}", orderCode, respXml);
log.info("[{}] prepay response: {}", orderCode, respXml);
return respXml;
}
... ... @@ -519,7 +534,7 @@ public abstract class AbstractWeixinPayService extends AbstractPayService {
}
//md5签名
String sign = WXUtils.signMd5(parameters, getMchKey());
String sign = signByMD5(parameters);
parameters.put(WeixinPayConfig.ApiConstants.SIGN, sign);
return parameters;
... ...
... ... @@ -20,20 +20,12 @@ public class WeixinMiniappPayService extends AbstractWeixinPayService {
return WeixinPayConfig.Miniapp.MALL_ID;
}
@Override
protected String getMchKey() {
return WeixinPayConfig.Miniapp.KEY;
}
@Override
protected String getAppId() {
return WeixinPayConfig.Miniapp.APPID;
}
@Override
protected String getMchCertPath() {
return WeixinPayConfig.WECHAT_PAY_UFOREAL_APP_PARTNER_CERT;
}
@Override
protected String getTradeType() {
... ...
package com.yohoufo.order.service.pay.weixin;
import com.yohoufo.common.utils.HttpClient;
import com.yohoufo.order.config.WeixinPayConfig;
import com.yohoufo.order.service.pay.weixin.ssl.WxAppHttpSslClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
@Service
public class WeixinPayAppService extends AbstractWeixinPayService {
// App 支付参数
@Value("${wechat.app.partnerid}")
private String mchid;
@Value("${wechat.app.partnerkey}")
private String mchkey;
@Value("${wechat.app.appid}")
private String appId;
@Autowired
private WxAppHttpSslClient httpSslClient;
@Override
protected String getMchId() {
return mchid;
}
@Override
protected String getMchKey() {
return mchkey;
}
@Override
protected String getAppId() {
return appId;
}
@Override
protected String getTradeType() {
return WeixinPayConfig.TRADE_TYPE_APP;
}
@Override
protected String getMchCertPath() {
return WeixinPayConfig.WECHAT_PAY_APP_PARTNER_CERT;
}
@Override
protected HttpClient getSslHttpClient() {
return httpSslClient;
}
}
package com.yohoufo.order.service.pay.weixin;
import com.yohoufo.common.utils.HttpClient;
import com.yohoufo.order.config.WeixinPayConfig;
import com.yohoufo.order.service.pay.weixin.ssl.WxBlkAppHttpSslClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class WeixinPayBlkAppService extends AbstractWeixinPayService {
@Autowired
private WxBlkAppHttpSslClient httpSslClient;
@Override
protected String getMchId() {
return WeixinPayConfig.PARTNER_BLK_APP;
}
@Override
protected String getMchKey() {
return WeixinPayConfig.PARTNER_KEY_BLK_APP;
}
@Override
protected String getAppId() {
return WeixinPayConfig.APP_ID_BLK;
}
@Override
protected String getMchCertPath() {
return WeixinPayConfig.WECHAT_PAY_BLKAPP_PARTNER_CERT;
}
@Override
protected String getTradeType() {
return WeixinPayConfig.TRADE_TYPE_APP;
}
@Override
protected HttpClient getSslHttpClient() {
return httpSslClient;
}
}
package com.yohoufo.order.service.pay.weixin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.yohoufo.common.utils.HttpClient;
import com.yohoufo.order.config.WeixinPayConfig;
import com.yohoufo.order.service.pay.weixin.ssl.WxUFOAppHttpSslClient;
@Service
public class WeixinPayUFOAppService extends AbstractWeixinPayService {
@Autowired
private WxUFOAppHttpSslClient httpSslClient;
@Override
protected String getMchId() {
return WeixinPayConfig.PARTNER_UFO_APP;
}
@Override
protected String getMchKey() {
return WeixinPayConfig.PARTNER_KEY_UFO_APP;
}
@Override
protected String getAppId() {
return WeixinPayConfig.APP_ID_UFO;
}
@Override
protected String getMchCertPath() {
return WeixinPayConfig.WECHAT_PAY_UFOAPP_PARTNER_CERT;
}
@Override
protected String getTradeType() {
return WeixinPayConfig.TRADE_TYPE_APP;
}
@Override
protected HttpClient getSslHttpClient() {
return httpSslClient;
}
}
... ... @@ -18,20 +18,12 @@ public class WeixinPayUFORealAppService extends AbstractWeixinPayService {
return WeixinPayConfig.PARTNER_UFO_REAL_APP;
}
@Override
protected String getMchKey() {
return WeixinPayConfig.PARTNER_KEY_UFO_REAL_APP;
}
@Override
protected String getAppId() {
return WeixinPayConfig.APP_ID_UFO_REAL;
}
@Override
protected String getMchCertPath() {
return WeixinPayConfig.WECHAT_PAY_UFOREAL_APP_PARTNER_CERT;
}
@Override
protected String getTradeType() {
... ...
package com.yohoufo.order.service.pay.weixin.ssl;
import com.yohoufo.order.config.WeixinPayConfig;
import org.springframework.stereotype.Component;
@Component
public class WxAppHttpSslClient extends HttpSslClientAbstract {
@Override
protected String getMchCertPath() {
return WeixinPayConfig.WECHAT_PAY_APP_PARTNER_CERT;
}
@Override
protected String getMchCertPassword() {
return WeixinPayConfig.PARTNER;
}
}
package com.yohoufo.order.service.pay.weixin.ssl;
import com.yohoufo.order.config.WeixinPayConfig;
import com.yohoufo.order.service.pay.weixin.ssl.HttpSslClientAbstract;
import org.springframework.stereotype.Component;
@Component
public class WxBlkAppHttpSslClient extends HttpSslClientAbstract {
@Override
protected String getMchCertPath() {
return WeixinPayConfig.WECHAT_PAY_BLKAPP_PARTNER_CERT;
}
@Override
protected String getMchCertPassword() {
return WeixinPayConfig.PARTNER_BLK_APP;
}
}
package com.yohoufo.order.service.pay.weixin.ssl;
import com.yohoufo.order.config.WeixinPayConfig;
import com.yohoufo.order.service.pay.weixin.ssl.HttpSslClientAbstract;
import org.springframework.stereotype.Component;
@Component
public class WxUFOAppHttpSslClient extends HttpSslClientAbstract {
@Override
protected String getMchCertPath() {
return WeixinPayConfig.WECHAT_PAY_UFOAPP_PARTNER_CERT;
}
@Override
protected String getMchCertPassword() {
return WeixinPayConfig.PARTNER_UFO_APP;
}
}
... ... @@ -145,6 +145,11 @@
<artifactId>lombok</artifactId>
<version>${lombok.version}</version>
</dependency>
<dependency>
<groupId>com.yoho.core</groupId>
<artifactId>security</artifactId>
<version>1.6.5-SNAPSHOT</version>
</dependency>
</dependencies>
</dependencyManagement>
... ...