FastChar-Pay是基于FastChar的支付框架,通过FastChar-Pay插件可快速集成支付宝和微信支付功能,并提供api接口!开发者只要接收订单支付的结果即可,无需在做重复的支付宝和微信订单生成过程!使用步骤如下:
1、下载并引用FastChar-Pay到项目中。或通过maven如下:
<dependency>
<groupId>com.fastchar</groupId>
<artifactId>fastchar-pay</artifactId>
<version>1.0</version><!--具体版本请前往maven中心查看 https://mvnrepository.com/artifact/com.fastchar/fastchar-pay -->
</dependency>
public void onInit(FastEngine engine) throws Exception {
engine.getConfig(FastAliPayConfig.class)//配置支付宝的密钥信息
.setAppId("201****01")
.setPartner("2088***515")
.setAlgorithm("RSA2")
.setSeller("13****4@qq.com")
.setRsaPrivate("MIIEwA**********GU2Ipw=")
.setRsaPublic("MIIBIjAN****DAQAB");
engine.getConfig(FastWxPayConfig.class)//配置微信的密钥信息
.setAppId("wx*********7e1b")
.setMchId("154*****481")
.setAppSecret("e66f**********c699cd")
.setApiKey("9b3e18*******7d72254");
}
public class OnPayListener implements IFastPayListener {
@Override
public void onPayCallBack(FinalPayOrderEntity orderEntity) {
if (orderEntity.getPayOrderState() == FinalPayOrderEntity.PayOrderStateEnum.已支付) {
orderEntity.setPayOrderState(FinalPayOrderEntity.PayOrderStateEnum.已完成);//设置订单状态为已完成,避免重复处理的问题!
orderEntity.update();
int userId = orderEntity.getUserId();//获取下单的用户Id
if (orderEntity.getPayOrderCode().startsWith("KQ")) { //购买卡券
} else if (orderEntity.getPayOrderCode().startsWith("TC")) { //购买套餐
} else if (orderEntity.getPayOrderCode().startsWith("SP")) { //购买商品
} else if (orderEntity.getPayOrderCode().startsWith("SK")) {//线下付款
}else if (orderEntity.getPayOrderCode().startsWith("HY")) {//购买会员
}
}
}
}
如上OnPayListener实现了IFastPayListener接口,然后注册到代理器中即可接收订单支付的结果!
4、通知手机端调用对应的api接口
如果项目中也集成了FastChar-ExtJs插件,那么在集成FastChar-Pay框架后,系统自动生成FastChar-Pay提供的支付api接口文档,接口文档的路径为:项目主路径+"/doc",
例如:项目主路径为:http://192.168.0.1:8080/fastcharweb/
那么访问接口文档的路径为:http://192.168.0.1:8080/fastcharweb/doc
然后手机端调用对应的支付接口文档,就可以获取发起支付宝或微信支付的必要参数信息!
api接口文档在线示例:https://www.fastchar.com/doc