|
@@ -0,0 +1,170 @@
|
|
|
|
+package com.jpsoft.picc.modules.pay.controller;
|
|
|
|
+
|
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
|
+import com.jpsoft.picc.modules.base.entity.TransactionRecord;
|
|
|
|
+import com.jpsoft.picc.modules.base.service.CompanyService;
|
|
|
|
+import com.jpsoft.picc.modules.base.service.TransactionRecordService;
|
|
|
|
+import com.jpsoft.picc.modules.common.dto.MessageResult;
|
|
|
|
+import com.jpsoft.picc.modules.common.utils.SignUtil;
|
|
|
|
+import io.swagger.annotations.Api;
|
|
|
|
+import io.swagger.annotations.ApiImplicitParam;
|
|
|
|
+import io.swagger.annotations.ApiImplicitParams;
|
|
|
|
+import io.swagger.annotations.ApiOperation;
|
|
|
|
+import org.apache.commons.lang3.StringUtils;
|
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
|
+import org.springframework.stereotype.Controller;
|
|
|
|
+import org.springframework.web.bind.annotation.GetMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.PathVariable;
|
|
|
|
+import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
|
+import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
+
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
|
+import java.util.Date;
|
|
|
|
+import java.util.HashMap;
|
|
|
|
+import java.util.Map;
|
|
|
|
+
|
|
|
|
+/**
|
|
|
|
+ * @author 墨鱼_mo
|
|
|
|
+ * @date 2020-2-11 12:37
|
|
|
|
+ */
|
|
|
|
+
|
|
|
|
+@Controller
|
|
|
|
+@RequestMapping("/pay")
|
|
|
|
+@Api("支付")
|
|
|
|
+public class Pay {
|
|
|
|
+
|
|
|
|
+ @Value("${notifyBackUrl}")
|
|
|
|
+ private String notifyBackUrl;
|
|
|
|
+
|
|
|
|
+ @Value("${synchroBackUrl}")
|
|
|
|
+ private String synchroBackUrl;
|
|
|
|
+
|
|
|
|
+ @Value("${jpcloudUrl}")
|
|
|
|
+ private String jpcloudUrl;
|
|
|
|
+
|
|
|
|
+ @Value("${sellerSerialNumber}")
|
|
|
|
+ private String sellerSerialNumber;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private TransactionRecordService transactionRecordService;
|
|
|
|
+
|
|
|
|
+ @Autowired
|
|
|
|
+ private CompanyService companyService;
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ @ResponseBody
|
|
|
|
+ @ApiOperation(value="支付")
|
|
|
|
+ @ApiImplicitParam(name = "id",value = "流水号id", required = true)
|
|
|
|
+ @RequestMapping(value="/paySubmit/{id}")
|
|
|
|
+ public MessageResult paySubmit(HttpServletRequest request, @PathVariable("id") String id){
|
|
|
|
+
|
|
|
|
+ //TODO 买家串号获取修改
|
|
|
|
+ TransactionRecord transactionRecord = transactionRecordService.get(id);
|
|
|
|
+
|
|
|
|
+ // AttributePrincipal principal = (AttributePrincipal) request.getUserPrincipal();
|
|
|
|
+ // Company company = companyService.findBy(principal.getName());
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ HashMap<String,Object> paramMap = new HashMap<String,Object>();
|
|
|
|
+ paramMap.put("orderNo", transactionRecord.getOrderNo());
|
|
|
|
+ paramMap.put("orderName", "PICC");
|
|
|
|
+ paramMap.put("freezeTime", transactionRecord.getCreateTime().getTime()/1000);
|
|
|
|
+ paramMap.put("unfreezeTime", transactionRecord.getCreateTime().getTime()/1000);
|
|
|
|
+ paramMap.put("orderAmount", transactionRecord.getAmount());
|
|
|
|
+ paramMap.put("code", "0008");
|
|
|
|
+ paramMap.put("buyerSerialNumber", "000101000178");//取登录用户的ID
|
|
|
|
+ paramMap.put("sellerSerialNumber", sellerSerialNumber);
|
|
|
|
+ paramMap.put("notifyBackUrl", notifyBackUrl);
|
|
|
|
+ paramMap.put("synchroBackUrl", synchroBackUrl);
|
|
|
|
+ String sign = SignUtil.createSign(paramMap, "1234567890");
|
|
|
|
+ paramMap.put("sign", sign);
|
|
|
|
+
|
|
|
|
+ String param = "";
|
|
|
|
+
|
|
|
|
+ for (Map.Entry<String, Object> map : paramMap.entrySet()) {
|
|
|
|
+ param += map.getKey() + "=" + map.getValue() + "&";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if(StringUtils.isNotBlank(param)){
|
|
|
|
+ param = param.substring(0,param.length()-1);
|
|
|
|
+ }
|
|
|
|
+ String returnUrl=jpcloudUrl+"?"+param;
|
|
|
|
+ MessageResult msgResult = new MessageResult<>();
|
|
|
|
+ msgResult.setData(returnUrl);
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @RequestMapping(value = "/orderNotifyBack")
|
|
|
|
+ @ResponseBody
|
|
|
|
+ public MessageResult<?> orderNotifyBack(HttpServletRequest req,String payTime,String payType,String orderNo,String sign) {
|
|
|
|
+ HashMap<String, Object> retMap = new HashMap<String, Object>();
|
|
|
|
+
|
|
|
|
+ String status = "success";
|
|
|
|
+ String message = "订单支付成功";
|
|
|
|
+ JSONObject body = new JSONObject();
|
|
|
|
+ System.out.println("payTime>>>" + payTime + "paymentType>>>" + payType + ">>>>orderNo>>" + orderNo + "sign>>>" + sign);
|
|
|
|
+ if(StringUtils.isNotBlank(payType) && StringUtils.isNotBlank(orderNo)){
|
|
|
|
+
|
|
|
|
+ HashMap<String,Object> signMap = new HashMap<String,Object>();
|
|
|
|
+
|
|
|
|
+ Map<String,String[]> paramMap = req.getParameterMap();
|
|
|
|
+
|
|
|
|
+ for (Map.Entry<String, String[]> map : paramMap.entrySet()) {
|
|
|
|
+ if(!"sign".equals(map.getKey())){
|
|
|
|
+ signMap.put(map.getKey(), map.getValue()[0]);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ // String signKey = ReadPropertiesUtils.getProperty("thirdInfo", "signKey");
|
|
|
|
+ boolean result = SignUtil.validateSign(signMap,"1234567890",sign);
|
|
|
|
+
|
|
|
|
+ if(result){
|
|
|
|
+ TransactionRecord transactionRecord = transactionRecordService.getByOrderNo(orderNo);
|
|
|
|
+ if(transactionRecord != null && transactionRecord.getPaymentStatus() != "20"){
|
|
|
|
+ transactionRecord.setPaymentStatus("20");
|
|
|
|
+ transactionRecord.setPaymentTime(new Date());
|
|
|
|
+ transactionRecord.setBuyType(payType);
|
|
|
|
+ transactionRecordService.update(transactionRecord);
|
|
|
|
+
|
|
|
|
+ body.put("orderNo", orderNo);
|
|
|
|
+ body.put("backStatus", "回调成功");
|
|
|
|
+ body.put("backTime", new Date().getTime()/1000);
|
|
|
|
+ }else if(transactionRecord == null){
|
|
|
|
+ message = "订单不存在";
|
|
|
|
+ status = "fail";
|
|
|
|
+ }else if("20".equals(transactionRecord.getPaymentStatus())){
|
|
|
|
+ message = "订单已支付";
|
|
|
|
+ status = "fail";
|
|
|
|
+ }
|
|
|
|
+ }else{
|
|
|
|
+ message = "签名不正确";
|
|
|
|
+ status = "fail";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }else{
|
|
|
|
+ message = "订单号不存在";
|
|
|
|
+ status = "fail";
|
|
|
|
+ }
|
|
|
|
+ retMap.put("status", status);
|
|
|
|
+ retMap.put("message", message);
|
|
|
|
+ retMap.put("body", body);
|
|
|
|
+ MessageResult msgResult = new MessageResult<>();
|
|
|
|
+ msgResult.setData(retMap);
|
|
|
|
+ msgResult.setResult(true);
|
|
|
|
+
|
|
|
|
+ return msgResult;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @GetMapping(value="/paySuccess")
|
|
|
|
+ @ApiOperation(value="返回前端")
|
|
|
|
+ public String paySuccess(){
|
|
|
|
+ return "redirect:/portal/";
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+}
|