SpringBoot project docking micro letter backstage pay development - micro-channel single unified interface development

I did not find sdk micro-channel pay. According to the official himself to the pure handwriting interface documentation, various xml turn JSON, JSON turn xml, encryption and decryption, signature ,,,, collapse of the whole people are

Development of the third day, found the official sdk. Mood suddenly see the light all of a sudden, the people are relaxed part of it.

Man of few words said, directly on the code

The first is the introduction of micro-channel dependencies pay it

<dependency> 
<the groupId> com.github.wxpay </ the groupId>
<the artifactId> wxpay-SDK </ the artifactId>
<Version> 0.0.3 </ Version>
</ dependency>

we can look into the source inside the respective methods encapsulated was very good too, come from the native I burst into tears
following micro letter unified under a single interface development, for example
  / ** @description single uniform interface to the micro-channel 
* @author wenjing
* @date 2019/5/13 10:46
* @Param [wxUnifiedorderModel]
* @return com.zyhp.utils.Result
** /
public wxUnifiedorder the Result (WxUnifiedorderModel wxUnifiedorderModel ) throws Exception {
    // new new pay a micro channel, the actual development is preferably used singleton
MyWxConfig new new MyWxConfig config = ();
WXPay wxPay = new new WXPay (config);
a SortedMap <String, String> the params = new new the TreeMap <String, String> ();
params.put ( "DEVICE_INFO", "the WEB"); // device number
params.put ( "body", wxUnifiedorderModel.getBody ( )); // product description
// merchant order number generating
long serialNumMax = redisUtil.incr ( "outTradeNo");
String outTradeNo = CommonUtil.getDateStr(new Date())+serialNumMax;
wxUnifiedorderModel.setOutTradeNo(outTradeNo);
params.put("out_trade_no", outTradeNo);
params.put("total_fee", wxUnifiedorderModel.getTotalFee().movePointRight(2).toString());
// params.put("time_start", time_start);
params.put("trade_type","JSAPI");
params.put("notify_url",Constans.SERVICE_HOST+"/payInfoBack");
params.put("spbill_create_ip",wxUnifiedorderModel.getSpbillCreateIp());
Map<String,String> resultMap = wxPay.unifiedOrder(params);
if("FAIL".equals(resultMap.get("return_code"))) { }
Return new new the Result ( "-. 1", "parameter format error", null);

if("SUCCESS".equals(resultMap.get("result_code"))){
return new Result("-1",resultMap.get("err_code_des"),null);
}
//保存该订单记录
wxUnifiedorderModel.setTimeStart(new Date());
wxUnifiedorderModelMapper.insert(wxUnifiedorderModel);
return new Result("1","成功",resultMap.get("prepay_id"));
}

Guess you like

Origin www.cnblogs.com/wenjing-520/p/10870878.html