guess-paygateway-common
1、PartnerChargeService(业务操作接口)提供的方法:
创建合作商充值请求,客户端拿着参数直接请求合作商网关
ModelResult<PartnerChargeRequest> createChargeRequest
查询充值结果
ModelResult<PartnerChargeResult> queryPartnerChargeResult
退款
ModelResult<PartnerRefundResult> createRefundRequest
2、PartnerChargeWay(充值方式:支付、微信、微博等)
以上是common里的,PartnerChargeService 是直接给外面调用的业务接口,给客户端请求网关用的,所有支付方式的充值都走这个接口。
guess-paygateway-server
1、PartnerFactory:里面就放了一个map,key:支付方式,value:支付方式对应的接口
private Map<Integer, PartnerChargeProtocal> chargeProxys = Maps.newHashMap();
这个map的get方法:
public Map<Integer, PartnerChargeProtocal> getChargeProxys() {
return chargeProxys;
}
set:这里注入了一个List<PartnerChargeProtocal>,会把继承PartnerChargeProtocal的实例注入进来,当然这些实例要在spring容器中,然后将放到这个map中。
@Autowired(required=false)
public void setChargeProxys(List<PartnerChargeProtocal> chargeProxyList) {
if (chargeProxyList.size() > 0) {
for (PartnerChargeProtocal proxy : chargeProxyList) {
chargeProxys.put(proxy.getChargeWay(), proxy);
}
}
}
2、PartnerChargeProtocal(第三方业务操作接口)网关用于请求第三方的接口
充值
PartnerChargeRequest createChargeRequest(CreateChargeRequestParam chargeParam)
查询充值结果
queryPartnerChargeResult
......
3、WeiboWapPaymentProtoImpl,微博支付方式的具体实现类,继承PartnerChargeProtocal,还继承了BaseWeiboProtocalImpl,这个是发起请求用的工具类。
充值示例:
@Override
public PartnerChargeRequest createChargeRequest(CreateChargeRequestParam chargeParam) throws Exception {
PartnerChargeRequest result = new PartnerChargeRequest();
BigDecimal amountStr = chargeParam.getAmount();
if (amountStr.compareTo(BigDecimal.ZERO) <= 0)
throw new PayGateWayException(new ErrorCode("payment.amount.not.lessthen.zero", "充值金额须大于0"));
Map<String,String> params = new HashMap<String, String>();
params.put("seller_id", appId);
params.put("appkey", appkey);
params.put("sign_type", "rsa");
params.put("notify_url", notifyUrl+"/wbpay/asynchPay");
params.put("out_pay_id", chargeParam.getChargeNo());
params.put("subject", chargeParam.getChargeName());
params.put("total_amount", MathUtils.magnified100(chargeParam.getAmount())+"");
params.put("body", chargeParam.getChargeName());
params.put("return_url", returnUrl+chargeParam.getReturnUrl());
params.put("expire", "300");
params.put("extra", "guess");
.....
}
4、aseWeiboProtocalImpl
protected String httpPost(String logInfo,String gateWay, Map<String, String> paramMap) {
try {
logger.info("【{}】传递参数:[{}],域名:[{}]", logInfo,JSON.toJSONString(paramMap),gateWay);
String retString = HttpSSLUtil.httpSSLClientPost(gateWay, paramMap, "UTF-8");
logger.info("【{}】接口返回数据:[{}],域名:[{}]", logInfo,retString,gateWay);
return retString;
} catch (Exception e) {
logger.error("【{}】调用接口发生异常,域名:[{}]", logInfo,gateWay,e);
throw e;
}
}