mirror of
https://gitee.com/elegant_wings/dbd-meeting.git
synced 2025-06-21 17:09:36 +08:00
Merge branch 'shoot-hand' of https://gitee.com/elegant_wings/dbd-meeting into shoot-hand
This commit is contained in:
commit
8ed02a61ec
@ -17,6 +17,7 @@ import com.ics.admin.service.IRepairAddressFloorService;
|
||||
import org.wf.jwtp.annotation.RequiresPermissions;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
/**
|
||||
* 地点楼层
|
||||
@ -67,6 +68,11 @@ public class RepairAddressFloorController extends BaseController {
|
||||
@RequiresPermissions("floor:floor:add")
|
||||
@PostMapping("save")
|
||||
public R addSave(@RequestBody RepairAddressFloor repairAddressFloor) {
|
||||
IcsCustomerStaff staff = new IcsCustomerStaff();
|
||||
staff.setId(repairAddressFloor.getAdminId());
|
||||
staff.setDataType("9");
|
||||
customerStaffService.updateIcsCustomerStaff(staff);
|
||||
|
||||
return toAjax(repairAddressFloorService.insertRepairAddressFloor(repairAddressFloor));
|
||||
}
|
||||
|
||||
@ -76,6 +82,21 @@ public class RepairAddressFloorController extends BaseController {
|
||||
@RequiresPermissions("floor:floor:edit")
|
||||
@PostMapping("update")
|
||||
public R editSave(@RequestBody RepairAddressFloor repairAddressFloor) {
|
||||
Long id = repairAddressFloor.getId();
|
||||
RepairAddressFloor addressFloor = repairAddressFloorService.selectRepairAddressFloorById(id);
|
||||
if (addressFloor != null) {
|
||||
Long adminId = addressFloor.getAdminId();
|
||||
if (!Objects.equals(repairAddressFloor.getAdminId(), adminId)) {
|
||||
IcsCustomerStaff staff = customerStaffService.selectIcsCustomerStaffById(repairAddressFloor.getAdminId());
|
||||
if (staff != null)
|
||||
staff.setDataType("9");
|
||||
customerStaffService.updateIcsCustomerStaff(staff);
|
||||
IcsCustomerStaff staff1 = customerStaffService.selectIcsCustomerStaffById(adminId);
|
||||
staff1.setDataType("1");
|
||||
customerStaffService.updateIcsCustomerStaff(staff1);
|
||||
}
|
||||
|
||||
}
|
||||
return toAjax(repairAddressFloorService.updateRepairAddressFloor(repairAddressFloor));
|
||||
}
|
||||
|
||||
|
@ -21,7 +21,7 @@ import com.ics.common.core.domain.IcsCustomerStaff;
|
||||
import com.ics.common.core.domain.R;
|
||||
import com.ics.common.core.page.PageDomain;
|
||||
import com.ics.common.core.page.TableSupport;
|
||||
import com.ics.controller.mobile.pay.wx.WxPayCommon;
|
||||
//import com.ics.controller.mobile.pay.wx.WxPayCommon;
|
||||
import com.ics.controller.mobile.pay.wx.constant.WxNotifyConstants;
|
||||
import com.ics.controller.mobile.pay.wx.dto.WxChatBasePayDto;
|
||||
import com.ics.controller.mobile.pay.wx.dto.WxChatPayDto;
|
||||
@ -75,8 +75,8 @@ public class ApiRoomContentController extends BaseController {
|
||||
@Autowired
|
||||
private IRoomEquipmentService roomEquipmentService;
|
||||
|
||||
@Autowired
|
||||
WxPayCommon wxPayCommon;
|
||||
// @Autowired
|
||||
// WxPayCommon wxPayCommon;
|
||||
|
||||
@Autowired
|
||||
private IUserEquipmentService userEquipmentService;
|
||||
@ -260,8 +260,8 @@ public class ApiRoomContentController extends BaseController {
|
||||
wxChatBasePayDto.setPrice(price);
|
||||
wxChatBasePayDto.setNotify(WxNotifyConstants.CASE_PAY_NOTIFY);
|
||||
wxChatBasePayDto.setOpenId(customerStaff.getOpenid());
|
||||
String prepayId = wxPayCommon.wxJsApiPay(wxChatBasePayDto);
|
||||
reservation.setPrepayId(prepayId);
|
||||
// String prepayId = wxPayCommon.wxJsApiPay(wxChatBasePayDto);
|
||||
// reservation.setPrepayId(prepayId);
|
||||
reservation.setStauts(Reservation.Status.TO_BE_PAID);
|
||||
Long userId = reservation.getUserId();
|
||||
|
||||
|
@ -1,160 +1,160 @@
|
||||
package com.ics.controller.mobile.meeting;
|
||||
|
||||
import cn.hutool.core.lang.Assert;
|
||||
import com.google.gson.Gson;
|
||||
import com.ics.admin.domain.meeting.Reservation;
|
||||
import com.ics.admin.service.meeting.IReservationService;
|
||||
import com.ics.controller.mobile.pay.wx.WxPayCallbackUtil;
|
||||
import com.ics.controller.mobile.pay.wx.WxPayCommon;
|
||||
import com.ics.controller.mobile.pay.wx.dto.WxChatBasePayDto;
|
||||
import com.ics.controller.mobile.pay.wx.dto.WxChatPayDto;
|
||||
import com.ics.admin.service.meeting.ICustomerTicketService;
|
||||
import com.ics.common.core.controller.BaseController;
|
||||
import com.ics.common.core.domain.R;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 微信支付
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/meeting/wxPay")
|
||||
public class WxPayController extends BaseController {
|
||||
|
||||
@Autowired
|
||||
ICustomerTicketService customerTicketService;
|
||||
|
||||
@Autowired
|
||||
WxPayCommon wxPayCommon;
|
||||
|
||||
@Autowired
|
||||
WxPayCallbackUtil wxPayCallbackUtil;
|
||||
|
||||
@Autowired
|
||||
private IReservationService reservationService;
|
||||
|
||||
|
||||
/**
|
||||
* 下载
|
||||
*/
|
||||
@PostMapping("paySign")
|
||||
public R paySign(@RequestBody Reservation reservation) {
|
||||
// String prepayId = wxPayCommon.wxJsApiPay(wxChatBasePayDto);
|
||||
WxChatPayDto wxChatPayDto = wxPayCommon.wxPayCall(reservation.getPrepayId());
|
||||
return R.data(wxChatPayDto);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 订单支付后回调
|
||||
*/
|
||||
@PostMapping("orderCallBack")
|
||||
public HashMap orderCallBack(HttpServletRequest request, HttpServletResponse response) {
|
||||
HashMap<String, String> returnParam = new HashMap<>();
|
||||
try {
|
||||
Map<String, String> parseParam = wxPayCallbackUtil.wxChatPayCallback(request, response);
|
||||
// 交易状态
|
||||
// SUCCESS:支付成功
|
||||
// REFUND:转入退款
|
||||
// NOTPAY:未支付
|
||||
// CLOSED:已关闭
|
||||
// REVOKED:已撤销(付款码支付)
|
||||
// USERPAYING:用户支付中(付款码支付)
|
||||
// PAYERROR:支付失败(其他原因,如银行返回失败)
|
||||
String trade_state = parseParam.get("trade_state");
|
||||
// 商户订单号
|
||||
String out_trade_no = parseParam.get("out_trade_no");
|
||||
// 微信订单号
|
||||
String transaction_id = parseParam.get("transaction_id");
|
||||
//
|
||||
//支付成功
|
||||
if (trade_state.equals("SUCCESS")){
|
||||
//编写支付成功后逻辑
|
||||
System.out.println("订单支付后回调");
|
||||
Gson gson = new Gson();
|
||||
System.out.println(gson.toJson(parseParam));
|
||||
Reservation reservation = reservationService.selectByOrderNumber(out_trade_no);
|
||||
Assert.isTrue(reservation != null, "订单不存在");
|
||||
if (reservation.getStauts().equals(Reservation.Status.TO_BE_PAID)){
|
||||
reservation.setStauts(Reservation.Status.APPOINTMENT);
|
||||
reservation.setOrderTime(new Date());
|
||||
int i = reservationService.updateReservation(reservation);
|
||||
Assert.isTrue(i == 1, "更新失败");
|
||||
}
|
||||
}
|
||||
//响应微信
|
||||
returnParam.put("code", "SUCCESS");
|
||||
returnParam.put("message", "成功");
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return returnParam;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 商户订单号查询订单
|
||||
*/
|
||||
@PostMapping("wxMerchantOrderQuery")
|
||||
public HashMap wxMerchantOrderQuery(@RequestBody Map<String , String> paramMap) {
|
||||
HashMap<String, String> resultMap = wxPayCommon.wxMerchantOrderQuery(paramMap.get("outTradeNo"));
|
||||
|
||||
HashMap<Object, Object> map = new HashMap<>();
|
||||
// 商户订单号
|
||||
String out_trade_no = resultMap.get("out_trade_no");
|
||||
// 微信支付订单号
|
||||
String transaction_id = resultMap.get("transaction_id");
|
||||
Reservation reservation = reservationService.selectByOrderNumber(out_trade_no);
|
||||
|
||||
// 交易状态
|
||||
// * SUCCESS:支付成功
|
||||
// * REFUND:转入退款
|
||||
// * NOTPAY:未支付
|
||||
// * CLOSED:已关闭
|
||||
// * REVOKED:已撤销(仅付款码支付会返回)
|
||||
// * USERPAYING:用户支付中(仅付款码支付会返回)
|
||||
// * PAYERROR:支付失败(仅付款码支付会返回)
|
||||
String trade_state = resultMap.get("trade_state");
|
||||
if (trade_state.equals("SUCCESS")){
|
||||
//更新数据库
|
||||
Assert.isTrue(reservation != null, "订单不存在");
|
||||
reservation.setStauts(Reservation.Status.APPOINTMENT);
|
||||
reservation.setOrderTime(new Date());
|
||||
int i = reservationService.updateReservation(reservation);
|
||||
Assert.isTrue(i == 1, "更新失败");
|
||||
map.put("code", 200);
|
||||
map.put("msg", "支付成功");
|
||||
}else if (trade_state.equals("REFUND")){
|
||||
map.put("code", 500);
|
||||
map.put("msg", "转入退款");
|
||||
}else if (trade_state.equals("NOTPAY")){
|
||||
map.put("code", 500);
|
||||
map.put("msg", "未支付");
|
||||
}else if (trade_state.equals("CLOSED")){
|
||||
map.put("code", 500);
|
||||
map.put("msg", "已关闭");
|
||||
}else if (trade_state.equals("REVOKED")){
|
||||
map.put("code", 500);
|
||||
map.put("msg", "已撤销");
|
||||
}else if (trade_state.equals("USERPAYING")){
|
||||
map.put("code", 500);
|
||||
map.put("msg", "用户支付中");
|
||||
}else if (trade_state.equals("PAYERROR")){
|
||||
map.put("code", 500);
|
||||
map.put("msg", "支付失败");
|
||||
}else {
|
||||
map.put("code", 500);
|
||||
map.put("msg", "支付失败");
|
||||
}
|
||||
|
||||
return map;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//package com.ics.controller.mobile.meeting;
|
||||
//
|
||||
//import cn.hutool.core.lang.Assert;
|
||||
//import com.google.gson.Gson;
|
||||
//import com.ics.admin.domain.meeting.Reservation;
|
||||
//import com.ics.admin.service.meeting.IReservationService;
|
||||
//import com.ics.controller.mobile.pay.wx.WxPayCallbackUtil;
|
||||
//import com.ics.controller.mobile.pay.wx.WxPayCommon;
|
||||
//import com.ics.controller.mobile.pay.wx.dto.WxChatBasePayDto;
|
||||
//import com.ics.controller.mobile.pay.wx.dto.WxChatPayDto;
|
||||
//import com.ics.admin.service.meeting.ICustomerTicketService;
|
||||
//import com.ics.common.core.controller.BaseController;
|
||||
//import com.ics.common.core.domain.R;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.web.bind.annotation.*;
|
||||
//
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//import java.util.Date;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
//
|
||||
///**
|
||||
// * 微信支付
|
||||
// */
|
||||
//@RestController
|
||||
//@RequestMapping("/meeting/wxPay")
|
||||
//public class WxPayController extends BaseController {
|
||||
//
|
||||
// @Autowired
|
||||
// ICustomerTicketService customerTicketService;
|
||||
//
|
||||
// @Autowired
|
||||
// WxPayCommon wxPayCommon;
|
||||
//
|
||||
// @Autowired
|
||||
// WxPayCallbackUtil wxPayCallbackUtil;
|
||||
//
|
||||
// @Autowired
|
||||
// private IReservationService reservationService;
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 下载
|
||||
// */
|
||||
// @PostMapping("paySign")
|
||||
// public R paySign(@RequestBody Reservation reservation) {
|
||||
//// String prepayId = wxPayCommon.wxJsApiPay(wxChatBasePayDto);
|
||||
// WxChatPayDto wxChatPayDto = wxPayCommon.wxPayCall(reservation.getPrepayId());
|
||||
// return R.data(wxChatPayDto);
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 订单支付后回调
|
||||
// */
|
||||
// @PostMapping("orderCallBack")
|
||||
// public HashMap orderCallBack(HttpServletRequest request, HttpServletResponse response) {
|
||||
// HashMap<String, String> returnParam = new HashMap<>();
|
||||
// try {
|
||||
// Map<String, String> parseParam = wxPayCallbackUtil.wxChatPayCallback(request, response);
|
||||
// // 交易状态
|
||||
// // SUCCESS:支付成功
|
||||
// // REFUND:转入退款
|
||||
// // NOTPAY:未支付
|
||||
// // CLOSED:已关闭
|
||||
// // REVOKED:已撤销(付款码支付)
|
||||
// // USERPAYING:用户支付中(付款码支付)
|
||||
// // PAYERROR:支付失败(其他原因,如银行返回失败)
|
||||
// String trade_state = parseParam.get("trade_state");
|
||||
// // 商户订单号
|
||||
// String out_trade_no = parseParam.get("out_trade_no");
|
||||
// // 微信订单号
|
||||
// String transaction_id = parseParam.get("transaction_id");
|
||||
// //
|
||||
// //支付成功
|
||||
// if (trade_state.equals("SUCCESS")){
|
||||
// //编写支付成功后逻辑
|
||||
// System.out.println("订单支付后回调");
|
||||
// Gson gson = new Gson();
|
||||
// System.out.println(gson.toJson(parseParam));
|
||||
// Reservation reservation = reservationService.selectByOrderNumber(out_trade_no);
|
||||
// Assert.isTrue(reservation != null, "订单不存在");
|
||||
// if (reservation.getStauts().equals(Reservation.Status.TO_BE_PAID)){
|
||||
// reservation.setStauts(Reservation.Status.APPOINTMENT);
|
||||
// reservation.setOrderTime(new Date());
|
||||
// int i = reservationService.updateReservation(reservation);
|
||||
// Assert.isTrue(i == 1, "更新失败");
|
||||
// }
|
||||
// }
|
||||
// //响应微信
|
||||
// returnParam.put("code", "SUCCESS");
|
||||
// returnParam.put("message", "成功");
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return returnParam;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 商户订单号查询订单
|
||||
// */
|
||||
// @PostMapping("wxMerchantOrderQuery")
|
||||
// public HashMap wxMerchantOrderQuery(@RequestBody Map<String , String> paramMap) {
|
||||
// HashMap<String, String> resultMap = wxPayCommon.wxMerchantOrderQuery(paramMap.get("outTradeNo"));
|
||||
//
|
||||
// HashMap<Object, Object> map = new HashMap<>();
|
||||
// // 商户订单号
|
||||
// String out_trade_no = resultMap.get("out_trade_no");
|
||||
// // 微信支付订单号
|
||||
// String transaction_id = resultMap.get("transaction_id");
|
||||
// Reservation reservation = reservationService.selectByOrderNumber(out_trade_no);
|
||||
//
|
||||
// // 交易状态
|
||||
// // * SUCCESS:支付成功
|
||||
// // * REFUND:转入退款
|
||||
// // * NOTPAY:未支付
|
||||
// // * CLOSED:已关闭
|
||||
// // * REVOKED:已撤销(仅付款码支付会返回)
|
||||
// // * USERPAYING:用户支付中(仅付款码支付会返回)
|
||||
// // * PAYERROR:支付失败(仅付款码支付会返回)
|
||||
// String trade_state = resultMap.get("trade_state");
|
||||
// if (trade_state.equals("SUCCESS")){
|
||||
// //更新数据库
|
||||
// Assert.isTrue(reservation != null, "订单不存在");
|
||||
// reservation.setStauts(Reservation.Status.APPOINTMENT);
|
||||
// reservation.setOrderTime(new Date());
|
||||
// int i = reservationService.updateReservation(reservation);
|
||||
// Assert.isTrue(i == 1, "更新失败");
|
||||
// map.put("code", 200);
|
||||
// map.put("msg", "支付成功");
|
||||
// }else if (trade_state.equals("REFUND")){
|
||||
// map.put("code", 500);
|
||||
// map.put("msg", "转入退款");
|
||||
// }else if (trade_state.equals("NOTPAY")){
|
||||
// map.put("code", 500);
|
||||
// map.put("msg", "未支付");
|
||||
// }else if (trade_state.equals("CLOSED")){
|
||||
// map.put("code", 500);
|
||||
// map.put("msg", "已关闭");
|
||||
// }else if (trade_state.equals("REVOKED")){
|
||||
// map.put("code", 500);
|
||||
// map.put("msg", "已撤销");
|
||||
// }else if (trade_state.equals("USERPAYING")){
|
||||
// map.put("code", 500);
|
||||
// map.put("msg", "用户支付中");
|
||||
// }else if (trade_state.equals("PAYERROR")){
|
||||
// map.put("code", 500);
|
||||
// map.put("msg", "支付失败");
|
||||
// }else {
|
||||
// map.put("code", 500);
|
||||
// map.put("msg", "支付失败");
|
||||
// }
|
||||
//
|
||||
// return map;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
@ -1,157 +1,157 @@
|
||||
package com.ics.controller.mobile.pay.wx;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.wechat.pay.contrib.apache.httpclient.util.AesUtil;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import javax.servlet.ServletInputStream;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStreamReader;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.GeneralSecurityException;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
* 微信支付回调工具类
|
||||
*/
|
||||
@Component
|
||||
public class WxPayCallbackUtil {
|
||||
|
||||
@Autowired
|
||||
WxPayConfig wxPayConfig;
|
||||
|
||||
/**
|
||||
* 获取回调数据
|
||||
* @param request
|
||||
* @param response
|
||||
* @return
|
||||
*/
|
||||
public Map<String, String> wxChatPayCallback(HttpServletRequest request, HttpServletResponse response) {
|
||||
|
||||
//获取报文
|
||||
String body = getRequestBody(request);
|
||||
|
||||
//随机串
|
||||
String nonceStr = request.getHeader("Wechatpay-Nonce");
|
||||
|
||||
//微信传递过来的签名
|
||||
String signature = request.getHeader("Wechatpay-Signature");
|
||||
|
||||
//证书序列号(微信平台)
|
||||
String serialNo = request.getHeader("Wechatpay-Serial");
|
||||
|
||||
//时间戳
|
||||
String timestamp = request.getHeader("Wechatpay-Timestamp");
|
||||
|
||||
//构造签名串 应答时间戳\n,应答随机串\n,应答报文主体\n
|
||||
String signStr = Stream.of(timestamp, nonceStr, body).collect(Collectors.joining("\n", "", "\n"));
|
||||
|
||||
Map<String, String> map = new HashMap<>(2);
|
||||
try {
|
||||
//验证签名是否通过
|
||||
boolean result = verifiedSign(serialNo, signStr, signature);
|
||||
if(result){
|
||||
//解密数据
|
||||
String plainBody = decryptBody(body);
|
||||
return convertWechatPayMsgToMap(plainBody);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
/**
|
||||
* 转换body为map
|
||||
* @param plainBody
|
||||
* @return
|
||||
*/
|
||||
public Map<String,String> convertWechatPayMsgToMap(String plainBody){
|
||||
|
||||
Map<String,String> paramsMap = new HashMap<>(2);
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(plainBody);
|
||||
|
||||
//商户订单号
|
||||
paramsMap.put("out_trade_no",jsonObject.getString("out_trade_no"));
|
||||
//交易状态
|
||||
paramsMap.put("trade_state",jsonObject.getString("trade_state"));
|
||||
// 微信订单号
|
||||
paramsMap.put("transaction_id",jsonObject.getString("transaction_id"));
|
||||
|
||||
//附加数据
|
||||
paramsMap.put("attach",jsonObject.getString("attach"));
|
||||
if (jsonObject.getJSONObject("attach") != null && !jsonObject.getJSONObject("attach").equals("")){
|
||||
paramsMap.put("account_no",jsonObject.getJSONObject("attach").getString("accountNo"));
|
||||
}
|
||||
return paramsMap;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 解密body的密文
|
||||
*
|
||||
* "resource": {
|
||||
* "original_type": "transaction",
|
||||
* "algorithm": "AEAD_AES_256_GCM",
|
||||
* "ciphertext": "",
|
||||
* "associated_data": "",
|
||||
* "nonce": ""
|
||||
* }
|
||||
*
|
||||
* @param body
|
||||
* @return
|
||||
*/
|
||||
public String decryptBody(String body) throws UnsupportedEncodingException, GeneralSecurityException {
|
||||
AesUtil aesUtil = new AesUtil(wxPayConfig.getKey().getBytes("utf-8"));
|
||||
JSONObject object = JSONObject.parseObject(body);
|
||||
JSONObject resource = object.getJSONObject("resource");
|
||||
String ciphertext = resource.getString("ciphertext");
|
||||
String associatedData = resource.getString("associated_data");
|
||||
String nonce = resource.getString("nonce");
|
||||
return aesUtil.decryptToString(associatedData.getBytes("utf-8"),nonce.getBytes("utf-8"),ciphertext);
|
||||
}
|
||||
|
||||
/**
|
||||
* 验证签名
|
||||
*
|
||||
* @param serialNo 微信平台-证书序列号
|
||||
* @param signStr 自己组装的签名串
|
||||
* @param signature 微信返回的签名
|
||||
* @return
|
||||
* @throws UnsupportedEncodingException
|
||||
*/
|
||||
public boolean verifiedSign(String serialNo, String signStr, String signature) throws UnsupportedEncodingException {
|
||||
return wxPayConfig.getVerifier().verify(serialNo, signStr.getBytes("utf-8"), signature);
|
||||
}
|
||||
|
||||
/**
|
||||
* 读取请求数据流
|
||||
*
|
||||
* @param request
|
||||
* @return
|
||||
*/
|
||||
public String getRequestBody(HttpServletRequest request) {
|
||||
StringBuffer sb = new StringBuffer();
|
||||
try (ServletInputStream inputStream = request.getInputStream();
|
||||
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
) {
|
||||
String line;
|
||||
while ((line = reader.readLine()) != null) {
|
||||
sb.append(line);
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return sb.toString();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
//package com.ics.controller.mobile.pay.wx;
|
||||
//
|
||||
//import com.alibaba.fastjson.JSONObject;
|
||||
//import com.wechat.pay.contrib.apache.httpclient.util.AesUtil;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import javax.servlet.ServletInputStream;
|
||||
//import javax.servlet.http.HttpServletRequest;
|
||||
//import javax.servlet.http.HttpServletResponse;
|
||||
//import java.io.BufferedReader;
|
||||
//import java.io.IOException;
|
||||
//import java.io.InputStreamReader;
|
||||
//import java.io.UnsupportedEncodingException;
|
||||
//import java.security.GeneralSecurityException;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
//import java.util.stream.Collectors;
|
||||
//import java.util.stream.Stream;
|
||||
//
|
||||
///**
|
||||
// * 微信支付回调工具类
|
||||
// */
|
||||
//@Component
|
||||
//public class WxPayCallbackUtil {
|
||||
//
|
||||
// @Autowired
|
||||
// WxPayConfig wxPayConfig;
|
||||
//
|
||||
// /**
|
||||
// * 获取回调数据
|
||||
// * @param request
|
||||
// * @param response
|
||||
// * @return
|
||||
// */
|
||||
// public Map<String, String> wxChatPayCallback(HttpServletRequest request, HttpServletResponse response) {
|
||||
//
|
||||
// //获取报文
|
||||
// String body = getRequestBody(request);
|
||||
//
|
||||
// //随机串
|
||||
// String nonceStr = request.getHeader("Wechatpay-Nonce");
|
||||
//
|
||||
// //微信传递过来的签名
|
||||
// String signature = request.getHeader("Wechatpay-Signature");
|
||||
//
|
||||
// //证书序列号(微信平台)
|
||||
// String serialNo = request.getHeader("Wechatpay-Serial");
|
||||
//
|
||||
// //时间戳
|
||||
// String timestamp = request.getHeader("Wechatpay-Timestamp");
|
||||
//
|
||||
// //构造签名串 应答时间戳\n,应答随机串\n,应答报文主体\n
|
||||
// String signStr = Stream.of(timestamp, nonceStr, body).collect(Collectors.joining("\n", "", "\n"));
|
||||
//
|
||||
// Map<String, String> map = new HashMap<>(2);
|
||||
// try {
|
||||
// //验证签名是否通过
|
||||
// boolean result = verifiedSign(serialNo, signStr, signature);
|
||||
// if(result){
|
||||
// //解密数据
|
||||
// String plainBody = decryptBody(body);
|
||||
// return convertWechatPayMsgToMap(plainBody);
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return map;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 转换body为map
|
||||
// * @param plainBody
|
||||
// * @return
|
||||
// */
|
||||
// public Map<String,String> convertWechatPayMsgToMap(String plainBody){
|
||||
//
|
||||
// Map<String,String> paramsMap = new HashMap<>(2);
|
||||
//
|
||||
// JSONObject jsonObject = JSONObject.parseObject(plainBody);
|
||||
//
|
||||
// //商户订单号
|
||||
// paramsMap.put("out_trade_no",jsonObject.getString("out_trade_no"));
|
||||
// //交易状态
|
||||
// paramsMap.put("trade_state",jsonObject.getString("trade_state"));
|
||||
// // 微信订单号
|
||||
// paramsMap.put("transaction_id",jsonObject.getString("transaction_id"));
|
||||
//
|
||||
// //附加数据
|
||||
// paramsMap.put("attach",jsonObject.getString("attach"));
|
||||
// if (jsonObject.getJSONObject("attach") != null && !jsonObject.getJSONObject("attach").equals("")){
|
||||
// paramsMap.put("account_no",jsonObject.getJSONObject("attach").getString("accountNo"));
|
||||
// }
|
||||
// return paramsMap;
|
||||
//
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 解密body的密文
|
||||
// *
|
||||
// * "resource": {
|
||||
// * "original_type": "transaction",
|
||||
// * "algorithm": "AEAD_AES_256_GCM",
|
||||
// * "ciphertext": "",
|
||||
// * "associated_data": "",
|
||||
// * "nonce": ""
|
||||
// * }
|
||||
// *
|
||||
// * @param body
|
||||
// * @return
|
||||
// */
|
||||
// public String decryptBody(String body) throws UnsupportedEncodingException, GeneralSecurityException {
|
||||
// AesUtil aesUtil = new AesUtil(wxPayConfig.getKey().getBytes("utf-8"));
|
||||
// JSONObject object = JSONObject.parseObject(body);
|
||||
// JSONObject resource = object.getJSONObject("resource");
|
||||
// String ciphertext = resource.getString("ciphertext");
|
||||
// String associatedData = resource.getString("associated_data");
|
||||
// String nonce = resource.getString("nonce");
|
||||
// return aesUtil.decryptToString(associatedData.getBytes("utf-8"),nonce.getBytes("utf-8"),ciphertext);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 验证签名
|
||||
// *
|
||||
// * @param serialNo 微信平台-证书序列号
|
||||
// * @param signStr 自己组装的签名串
|
||||
// * @param signature 微信返回的签名
|
||||
// * @return
|
||||
// * @throws UnsupportedEncodingException
|
||||
// */
|
||||
// public boolean verifiedSign(String serialNo, String signStr, String signature) throws UnsupportedEncodingException {
|
||||
// return wxPayConfig.getVerifier().verify(serialNo, signStr.getBytes("utf-8"), signature);
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 读取请求数据流
|
||||
// *
|
||||
// * @param request
|
||||
// * @return
|
||||
// */
|
||||
// public String getRequestBody(HttpServletRequest request) {
|
||||
// StringBuffer sb = new StringBuffer();
|
||||
// try (ServletInputStream inputStream = request.getInputStream();
|
||||
// BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
|
||||
// ) {
|
||||
// String line;
|
||||
// while ((line = reader.readLine()) != null) {
|
||||
// sb.append(line);
|
||||
// }
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// return sb.toString();
|
||||
//
|
||||
// }
|
||||
//
|
||||
//}
|
||||
|
@ -1,253 +1,253 @@
|
||||
package com.ics.controller.mobile.pay.wx;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.ics.controller.mobile.pay.wx.constant.WxApiConstants;
|
||||
import com.ics.controller.mobile.pay.wx.dto.WxChatBasePayDto;
|
||||
import com.ics.controller.mobile.pay.wx.dto.WxChatPayDto;
|
||||
import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
import org.apache.http.client.methods.HttpGet;
|
||||
import org.apache.http.client.methods.HttpPost;
|
||||
import org.apache.http.entity.StringEntity;
|
||||
import org.apache.http.util.EntityUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.IOException;
|
||||
import java.math.BigDecimal;
|
||||
import java.security.Signature;
|
||||
import java.util.Base64;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
@Component
|
||||
public class WxPayCommon {
|
||||
|
||||
@Autowired
|
||||
WxPayConfig wxPayConfig;
|
||||
|
||||
|
||||
/**
|
||||
* 封装基础通用请求数据
|
||||
*
|
||||
* @param basePayData 微信支付基础请求数据
|
||||
* @return 封装后的map对象
|
||||
*/
|
||||
public Map<String, Object> getBasePayParams(WxChatBasePayDto basePayData) {
|
||||
Map<String, Object> paramsMap = new HashMap<>();
|
||||
paramsMap.put("appid", wxPayConfig.getAppid());
|
||||
paramsMap.put("mchid", wxPayConfig.getMchId());
|
||||
// 如果商品名称过长则截取
|
||||
String title = basePayData.getDescription().length() > 120 ? basePayData.getDescription().substring(0, 120) : basePayData.getDescription();
|
||||
paramsMap.put("description", title);
|
||||
paramsMap.put("out_trade_no", basePayData.getOrderId());
|
||||
paramsMap.put("notify_url", wxPayConfig.getNotifyDomain().concat(basePayData.getNotify()));
|
||||
Map<String, Integer> amountMap = new HashMap<>();
|
||||
amountMap.put("total", basePayData.getPrice().multiply(new BigDecimal("100")).intValue());
|
||||
paramsMap.put("amount", amountMap);
|
||||
return paramsMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求对象(Post请求)
|
||||
*
|
||||
* @param paramsMap 请求参数
|
||||
* @return Post请求对象
|
||||
*/
|
||||
public HttpPost getHttpPost(String url, Map<String, Object> paramsMap) {
|
||||
// 1.设置请求地址
|
||||
HttpPost httpPost = new HttpPost(wxPayConfig.getDomain().concat(url));
|
||||
|
||||
// 2.设置请求数据
|
||||
Gson gson = new Gson();
|
||||
String jsonParams = gson.toJson(paramsMap);
|
||||
|
||||
// 3.设置请求信息
|
||||
StringEntity entity = new StringEntity(jsonParams, "utf-8");
|
||||
entity.setContentType("application/json");
|
||||
httpPost.setEntity(entity);
|
||||
httpPost.setHeader("Accept", "application/json");
|
||||
return httpPost;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取请求对象(Get请求)
|
||||
*
|
||||
* @return Get请求
|
||||
*/
|
||||
public HttpGet getHttpGet(String url) {
|
||||
// 1.设置请求地址
|
||||
HttpGet httpGet = new HttpGet(wxPayConfig.getDomain().concat(url));
|
||||
// 3.设置请求信息
|
||||
httpGet.setHeader("Accept", "application/json");
|
||||
return httpGet;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 解析响应数据
|
||||
*
|
||||
* @param response 发送请求成功后,返回的数据
|
||||
* @return 微信返回的参数
|
||||
*/
|
||||
public HashMap<String, String> resolverResponse(CloseableHttpResponse response) {
|
||||
try {
|
||||
// 1.获取请求码
|
||||
int statusCode = response.getStatusLine().getStatusCode();
|
||||
// 2.获取返回值 String 格式
|
||||
final String bodyAsString = EntityUtils.toString(response.getEntity());
|
||||
|
||||
Gson gson = new Gson();
|
||||
if (statusCode == 200) {
|
||||
// 3.如果请求成功则解析成Map对象返回
|
||||
HashMap<String, String> resultMap = gson.fromJson(bodyAsString, HashMap.class);
|
||||
return resultMap;
|
||||
} else {
|
||||
if (StringUtils.isNoneBlank(bodyAsString)) {
|
||||
System.out.println("微信支付请求失败,提示信息:{}" + bodyAsString);
|
||||
// 4.请求码显示失败,则尝试获取提示信息
|
||||
HashMap<String, String> resultMap = gson.fromJson(bodyAsString, HashMap.class);
|
||||
throw new RuntimeException(resultMap.get("message"));
|
||||
}
|
||||
System.out.println("微信支付请求失败,未查询到原因,提示信息:{}" + response.toString());
|
||||
// 其他异常,微信也没有返回数据,这就需要具体排查了
|
||||
throw new IOException("request failed");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e.getMessage());
|
||||
} finally {
|
||||
try {
|
||||
response.close();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取签名
|
||||
*
|
||||
* @param nonceStr 随机数
|
||||
* @param appId 微信公众号或者小程序等的appid
|
||||
* @param prepay_id 预支付交易会话ID
|
||||
* @param timestamp 时间戳 10位
|
||||
* @return String 新签名
|
||||
*/
|
||||
String getSign(String nonceStr, String appId, String prepay_id, long timestamp) {
|
||||
|
||||
//从下往上依次生成
|
||||
String message = buildMessage(appId, timestamp, nonceStr, prepay_id);
|
||||
//签名
|
||||
try {
|
||||
return sign(message.getBytes("utf-8"));
|
||||
} catch (IOException e) {
|
||||
throw new RuntimeException("签名异常,请检查参数或商户私钥");
|
||||
}
|
||||
}
|
||||
|
||||
String sign(byte[] message) {
|
||||
try {
|
||||
//签名方式
|
||||
Signature sign = Signature.getInstance("SHA256withRSA");
|
||||
//私钥,通过MyPrivateKey来获取,这是个静态类可以接调用方法 ,需要的是_key.pem文件的绝对路径配上文件名
|
||||
sign.initSign(PemUtil.loadPrivateKey(new FileInputStream(wxPayConfig.getPrivateKeyPath())));
|
||||
sign.update(message);
|
||||
return Base64.getEncoder().encodeToString(sign.sign());
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException("签名异常,请检查参数或商户私钥");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 按照前端签名文档规范进行排序,\n是换行
|
||||
*
|
||||
* @param nonceStr 随机数
|
||||
* @param appId 微信公众号或者小程序等的appid
|
||||
* @param prepay_id 预支付交易会话ID
|
||||
* @param timestamp 时间戳 10位
|
||||
* @return String 新签名
|
||||
*/
|
||||
String buildMessage(String appId, long timestamp, String nonceStr, String prepay_id) {
|
||||
return appId + "\n"
|
||||
+ timestamp + "\n"
|
||||
+ nonceStr + "\n"
|
||||
+ prepay_id + "\n";
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 创建微信支付订单-jsapi方式
|
||||
*
|
||||
* @param basePayData 基础请求信息,商品标题、商家订单id、订单价格
|
||||
* @return 微信支付二维码地址
|
||||
*/
|
||||
public String wxJsApiPay(WxChatBasePayDto basePayData) {
|
||||
// 1.获取请求参数的Map格式
|
||||
Map<String, Object> paramsMap = getBasePayParams(basePayData);
|
||||
// 1.1 添加支付者信息
|
||||
Map<String, String> payerMap = new HashMap();
|
||||
payerMap.put("openid", basePayData.getOpenId());
|
||||
paramsMap.put("payer", payerMap);
|
||||
|
||||
// 2.获取请求对象
|
||||
HttpPost httpPost = getHttpPost(WxApiConstants.JSAPI_PAY, paramsMap);
|
||||
|
||||
// 3.完成签名并执行请求
|
||||
CloseableHttpResponse response = null;
|
||||
try {
|
||||
response = wxPayConfig.getWxPayClient().execute(httpPost);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("微信支付请求失败");
|
||||
}
|
||||
|
||||
// 4.解析response对象
|
||||
HashMap<String, String> resultMap = resolverResponse(response);
|
||||
if (resultMap != null) {
|
||||
// 【预支付交易会话标识】 预支付交易会话标识。用于后续接口调用中使用,该值有效期为2小时
|
||||
return resultMap.get("prepay_id");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* 微信用户调用微信支付
|
||||
*/
|
||||
public WxChatPayDto wxPayCall(String prepayId) {
|
||||
WxChatPayDto wxChatPayDto = new WxChatPayDto();
|
||||
wxChatPayDto.setAppid(wxPayConfig.getAppid());
|
||||
wxChatPayDto.setTimeStamp(String.valueOf(System.currentTimeMillis() / 1000));
|
||||
wxChatPayDto.setNonceStr(UUID.randomUUID().toString().replaceAll("-", ""));
|
||||
wxChatPayDto.setPrepayId("prepay_id=" + prepayId);
|
||||
wxChatPayDto.setSignType("RSA");
|
||||
wxChatPayDto.setPaySign(getSign(wxChatPayDto.getNonceStr(), wxChatPayDto.getAppid(), wxChatPayDto.getPrepayId(), Long.parseLong(wxChatPayDto.getTimeStamp())));
|
||||
|
||||
return wxChatPayDto;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 商户订单号查询订单
|
||||
*/
|
||||
public HashMap<String, String> wxMerchantOrderQuery(String outTradeNo) {
|
||||
// 创建请求
|
||||
HttpGet httpGet = getHttpGet(WxApiConstants.MERCHANT_ORDER_NUMBER_QUERY + "/" + outTradeNo + "?mchid=" + wxPayConfig.getMchId());
|
||||
// 完成签名并执行请求
|
||||
CloseableHttpResponse response = null;
|
||||
try {
|
||||
response = wxPayConfig.getWxPayClient().execute(httpGet);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException("商户订单号查询订单请求失败");
|
||||
}
|
||||
// 解析response对象
|
||||
HashMap<String, String> resultMap = resolverResponse(response);
|
||||
return resultMap;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
//package com.ics.controller.mobile.pay.wx;
|
||||
//
|
||||
//import com.google.gson.Gson;
|
||||
//import com.ics.controller.mobile.pay.wx.constant.WxApiConstants;
|
||||
//import com.ics.controller.mobile.pay.wx.dto.WxChatBasePayDto;
|
||||
//import com.ics.controller.mobile.pay.wx.dto.WxChatPayDto;
|
||||
//import com.wechat.pay.contrib.apache.httpclient.util.PemUtil;
|
||||
//import org.apache.commons.lang3.StringUtils;
|
||||
//import org.apache.http.client.methods.CloseableHttpResponse;
|
||||
//import org.apache.http.client.methods.HttpGet;
|
||||
//import org.apache.http.client.methods.HttpPost;
|
||||
//import org.apache.http.entity.StringEntity;
|
||||
//import org.apache.http.util.EntityUtils;
|
||||
//import org.springframework.beans.factory.annotation.Autowired;
|
||||
//import org.springframework.stereotype.Component;
|
||||
//
|
||||
//import java.io.FileInputStream;
|
||||
//import java.io.IOException;
|
||||
//import java.math.BigDecimal;
|
||||
//import java.security.Signature;
|
||||
//import java.util.Base64;
|
||||
//import java.util.HashMap;
|
||||
//import java.util.Map;
|
||||
//import java.util.UUID;
|
||||
//
|
||||
//@Component
|
||||
//public class WxPayCommon {
|
||||
//
|
||||
// @Autowired
|
||||
// WxPayConfig wxPayConfig;
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 封装基础通用请求数据
|
||||
// *
|
||||
// * @param basePayData 微信支付基础请求数据
|
||||
// * @return 封装后的map对象
|
||||
// */
|
||||
// public Map<String, Object> getBasePayParams(WxChatBasePayDto basePayData) {
|
||||
// Map<String, Object> paramsMap = new HashMap<>();
|
||||
// paramsMap.put("appid", wxPayConfig.getAppid());
|
||||
// paramsMap.put("mchid", wxPayConfig.getMchId());
|
||||
// // 如果商品名称过长则截取
|
||||
// String title = basePayData.getDescription().length() > 120 ? basePayData.getDescription().substring(0, 120) : basePayData.getDescription();
|
||||
// paramsMap.put("description", title);
|
||||
// paramsMap.put("out_trade_no", basePayData.getOrderId());
|
||||
// paramsMap.put("notify_url", wxPayConfig.getNotifyDomain().concat(basePayData.getNotify()));
|
||||
// Map<String, Integer> amountMap = new HashMap<>();
|
||||
// amountMap.put("total", basePayData.getPrice().multiply(new BigDecimal("100")).intValue());
|
||||
// paramsMap.put("amount", amountMap);
|
||||
// return paramsMap;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获取请求对象(Post请求)
|
||||
// *
|
||||
// * @param paramsMap 请求参数
|
||||
// * @return Post请求对象
|
||||
// */
|
||||
// public HttpPost getHttpPost(String url, Map<String, Object> paramsMap) {
|
||||
// // 1.设置请求地址
|
||||
// HttpPost httpPost = new HttpPost(wxPayConfig.getDomain().concat(url));
|
||||
//
|
||||
// // 2.设置请求数据
|
||||
// Gson gson = new Gson();
|
||||
// String jsonParams = gson.toJson(paramsMap);
|
||||
//
|
||||
// // 3.设置请求信息
|
||||
// StringEntity entity = new StringEntity(jsonParams, "utf-8");
|
||||
// entity.setContentType("application/json");
|
||||
// httpPost.setEntity(entity);
|
||||
// httpPost.setHeader("Accept", "application/json");
|
||||
// return httpPost;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获取请求对象(Get请求)
|
||||
// *
|
||||
// * @return Get请求
|
||||
// */
|
||||
// public HttpGet getHttpGet(String url) {
|
||||
// // 1.设置请求地址
|
||||
// HttpGet httpGet = new HttpGet(wxPayConfig.getDomain().concat(url));
|
||||
// // 3.设置请求信息
|
||||
// httpGet.setHeader("Accept", "application/json");
|
||||
// return httpGet;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 解析响应数据
|
||||
// *
|
||||
// * @param response 发送请求成功后,返回的数据
|
||||
// * @return 微信返回的参数
|
||||
// */
|
||||
// public HashMap<String, String> resolverResponse(CloseableHttpResponse response) {
|
||||
// try {
|
||||
// // 1.获取请求码
|
||||
// int statusCode = response.getStatusLine().getStatusCode();
|
||||
// // 2.获取返回值 String 格式
|
||||
// final String bodyAsString = EntityUtils.toString(response.getEntity());
|
||||
//
|
||||
// Gson gson = new Gson();
|
||||
// if (statusCode == 200) {
|
||||
// // 3.如果请求成功则解析成Map对象返回
|
||||
// HashMap<String, String> resultMap = gson.fromJson(bodyAsString, HashMap.class);
|
||||
// return resultMap;
|
||||
// } else {
|
||||
// if (StringUtils.isNoneBlank(bodyAsString)) {
|
||||
// System.out.println("微信支付请求失败,提示信息:{}" + bodyAsString);
|
||||
// // 4.请求码显示失败,则尝试获取提示信息
|
||||
// HashMap<String, String> resultMap = gson.fromJson(bodyAsString, HashMap.class);
|
||||
// throw new RuntimeException(resultMap.get("message"));
|
||||
// }
|
||||
// System.out.println("微信支付请求失败,未查询到原因,提示信息:{}" + response.toString());
|
||||
// // 其他异常,微信也没有返回数据,这就需要具体排查了
|
||||
// throw new IOException("request failed");
|
||||
// }
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// throw new RuntimeException(e.getMessage());
|
||||
// } finally {
|
||||
// try {
|
||||
// response.close();
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 获取签名
|
||||
// *
|
||||
// * @param nonceStr 随机数
|
||||
// * @param appId 微信公众号或者小程序等的appid
|
||||
// * @param prepay_id 预支付交易会话ID
|
||||
// * @param timestamp 时间戳 10位
|
||||
// * @return String 新签名
|
||||
// */
|
||||
// String getSign(String nonceStr, String appId, String prepay_id, long timestamp) {
|
||||
//
|
||||
// //从下往上依次生成
|
||||
// String message = buildMessage(appId, timestamp, nonceStr, prepay_id);
|
||||
// //签名
|
||||
// try {
|
||||
// return sign(message.getBytes("utf-8"));
|
||||
// } catch (IOException e) {
|
||||
// throw new RuntimeException("签名异常,请检查参数或商户私钥");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// String sign(byte[] message) {
|
||||
// try {
|
||||
// //签名方式
|
||||
// Signature sign = Signature.getInstance("SHA256withRSA");
|
||||
// //私钥,通过MyPrivateKey来获取,这是个静态类可以接调用方法 ,需要的是_key.pem文件的绝对路径配上文件名
|
||||
// sign.initSign(PemUtil.loadPrivateKey(new FileInputStream(wxPayConfig.getPrivateKeyPath())));
|
||||
// sign.update(message);
|
||||
// return Base64.getEncoder().encodeToString(sign.sign());
|
||||
// } catch (Exception e) {
|
||||
// throw new RuntimeException("签名异常,请检查参数或商户私钥");
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 按照前端签名文档规范进行排序,\n是换行
|
||||
// *
|
||||
// * @param nonceStr 随机数
|
||||
// * @param appId 微信公众号或者小程序等的appid
|
||||
// * @param prepay_id 预支付交易会话ID
|
||||
// * @param timestamp 时间戳 10位
|
||||
// * @return String 新签名
|
||||
// */
|
||||
// String buildMessage(String appId, long timestamp, String nonceStr, String prepay_id) {
|
||||
// return appId + "\n"
|
||||
// + timestamp + "\n"
|
||||
// + nonceStr + "\n"
|
||||
// + prepay_id + "\n";
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 创建微信支付订单-jsapi方式
|
||||
// *
|
||||
// * @param basePayData 基础请求信息,商品标题、商家订单id、订单价格
|
||||
// * @return 微信支付二维码地址
|
||||
// */
|
||||
// public String wxJsApiPay(WxChatBasePayDto basePayData) {
|
||||
// // 1.获取请求参数的Map格式
|
||||
// Map<String, Object> paramsMap = getBasePayParams(basePayData);
|
||||
// // 1.1 添加支付者信息
|
||||
// Map<String, String> payerMap = new HashMap();
|
||||
// payerMap.put("openid", basePayData.getOpenId());
|
||||
// paramsMap.put("payer", payerMap);
|
||||
//
|
||||
// // 2.获取请求对象
|
||||
// HttpPost httpPost = getHttpPost(WxApiConstants.JSAPI_PAY, paramsMap);
|
||||
//
|
||||
// // 3.完成签名并执行请求
|
||||
// CloseableHttpResponse response = null;
|
||||
// try {
|
||||
// response = wxPayConfig.getWxPayClient().execute(httpPost);
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// throw new RuntimeException("微信支付请求失败");
|
||||
// }
|
||||
//
|
||||
// // 4.解析response对象
|
||||
// HashMap<String, String> resultMap = resolverResponse(response);
|
||||
// if (resultMap != null) {
|
||||
// // 【预支付交易会话标识】 预支付交易会话标识。用于后续接口调用中使用,该值有效期为2小时
|
||||
// return resultMap.get("prepay_id");
|
||||
// }
|
||||
// return null;
|
||||
// }
|
||||
//
|
||||
// /**
|
||||
// * 微信用户调用微信支付
|
||||
// */
|
||||
// public WxChatPayDto wxPayCall(String prepayId) {
|
||||
// WxChatPayDto wxChatPayDto = new WxChatPayDto();
|
||||
// wxChatPayDto.setAppid(wxPayConfig.getAppid());
|
||||
// wxChatPayDto.setTimeStamp(String.valueOf(System.currentTimeMillis() / 1000));
|
||||
// wxChatPayDto.setNonceStr(UUID.randomUUID().toString().replaceAll("-", ""));
|
||||
// wxChatPayDto.setPrepayId("prepay_id=" + prepayId);
|
||||
// wxChatPayDto.setSignType("RSA");
|
||||
// wxChatPayDto.setPaySign(getSign(wxChatPayDto.getNonceStr(), wxChatPayDto.getAppid(), wxChatPayDto.getPrepayId(), Long.parseLong(wxChatPayDto.getTimeStamp())));
|
||||
//
|
||||
// return wxChatPayDto;
|
||||
// }
|
||||
//
|
||||
//
|
||||
// /**
|
||||
// * 商户订单号查询订单
|
||||
// */
|
||||
// public HashMap<String, String> wxMerchantOrderQuery(String outTradeNo) {
|
||||
// // 创建请求
|
||||
// HttpGet httpGet = getHttpGet(WxApiConstants.MERCHANT_ORDER_NUMBER_QUERY + "/" + outTradeNo + "?mchid=" + wxPayConfig.getMchId());
|
||||
// // 完成签名并执行请求
|
||||
// CloseableHttpResponse response = null;
|
||||
// try {
|
||||
// response = wxPayConfig.getWxPayClient().execute(httpGet);
|
||||
// } catch (IOException e) {
|
||||
// e.printStackTrace();
|
||||
// throw new RuntimeException("商户订单号查询订单请求失败");
|
||||
// }
|
||||
// // 解析response对象
|
||||
// HashMap<String, String> resultMap = resolverResponse(response);
|
||||
// return resultMap;
|
||||
// }
|
||||
//
|
||||
//
|
||||
//}
|
||||
|
@ -19,9 +19,9 @@ import java.io.FileNotFoundException;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.security.PrivateKey;
|
||||
|
||||
@Configuration
|
||||
@PropertySource("classpath:application.yml") //读取配置文件
|
||||
@ConfigurationProperties(prefix = "weixin") //读取wxpay节点
|
||||
//@Configuration
|
||||
//@PropertySource("classpath:application.yml") //读取配置文件
|
||||
//@ConfigurationProperties(prefix = "weixin") //读取wxpay节点
|
||||
@Data
|
||||
/**
|
||||
* 微信支付静态常量类
|
||||
@ -83,7 +83,7 @@ public class WxPayConfig {
|
||||
/**
|
||||
* 获取签名验证器
|
||||
*/
|
||||
@Bean
|
||||
// @Bean
|
||||
public Verifier getVerifier() {
|
||||
// 获取商户私钥
|
||||
final PrivateKey privateKey = getPrivateKey(privateKeyPath);
|
||||
@ -116,7 +116,7 @@ public class WxPayConfig {
|
||||
* 获取微信支付的远程请求对象
|
||||
* @return Http请求对象
|
||||
*/
|
||||
@Bean
|
||||
// @Bean
|
||||
public CloseableHttpClient getWxPayClient() {
|
||||
|
||||
// 获取签名验证器
|
||||
|
@ -1,7 +1,7 @@
|
||||
spring:
|
||||
redis:
|
||||
database: 1
|
||||
host: 127.0.0.1
|
||||
host: 222.184.49.22
|
||||
port: 6379
|
||||
password: 123456
|
||||
timeout: 6000ms # 连接超时时长(毫秒)
|
||||
@ -17,9 +17,9 @@ spring:
|
||||
druid:
|
||||
# 主库数据源
|
||||
master:
|
||||
url: jdbc:mysql://127.0.0.1:3306/dbd-meeting?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
url: jdbc:mysql://222.184.49.22:3306/shoot-hand?useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=convertToNull&useSSL=true&serverTimezone=GMT%2B8
|
||||
username: root
|
||||
password: Boyue1!Z
|
||||
password: boyue1!Z
|
||||
# 从库数据源
|
||||
slave:
|
||||
#从数据源开关/默认关闭
|
||||
@ -65,12 +65,12 @@ spring:
|
||||
multi-statement-allow: true
|
||||
servlet:
|
||||
multipart:
|
||||
location: /usr/local/uploadPath/
|
||||
location: /file/uploadPath/
|
||||
|
||||
# 本地文件上传路径
|
||||
dfs:
|
||||
path: /usr/local/uploadPath/
|
||||
domain: https://www.chuangzhikj.com//saas-ics
|
||||
path: /file/uploadPath/
|
||||
domain: https://company.haxy.com.cn:4443/shoot-hand
|
||||
# domain: http://39.165.217.47:81/saas-ics/
|
||||
# domain: https://www.xxxx.com/
|
||||
# 公众号配置(必填)
|
||||
@ -88,7 +88,7 @@ wx:
|
||||
key-prefix: wa # 相关redis前缀配置: wa(默认)
|
||||
redis:
|
||||
host: localhost
|
||||
# password: vdcity2015
|
||||
# password: vdcity2015
|
||||
port: 6379
|
||||
# http客户端配置
|
||||
http-client-type: HttpClient # http客户端类型: HttpClient(默认), OkHttp, JoddHttp
|
||||
|
Loading…
x
Reference in New Issue
Block a user