修改微信支付配置

This commit is contained in:
yuyang 2022-01-10 10:50:05 +08:00
parent e70cc61941
commit e675e8e795
3 changed files with 27 additions and 29 deletions

View File

@ -13,8 +13,10 @@ import com.xhpc.common.security.service.TokenService;
import com.xhpc.common.util.UserTypeUtil; import com.xhpc.common.util.UserTypeUtil;
import com.xhpc.payment.domain.XhpcAppUser; import com.xhpc.payment.domain.XhpcAppUser;
import com.xhpc.common.domain.XhpcRechargeOrder; import com.xhpc.common.domain.XhpcRechargeOrder;
import com.xhpc.payment.domain.XhpcSettingConfig;
import com.xhpc.payment.domain.XhpcUserAccountStatement; import com.xhpc.payment.domain.XhpcUserAccountStatement;
import com.xhpc.payment.mapper.XhpcUserAccountStatementMapper; import com.xhpc.payment.mapper.XhpcUserAccountStatementMapper;
import com.xhpc.payment.service.IXhpcCommonPayment;
import com.xhpc.payment.service.IXhpcRechargeOrderService; import com.xhpc.payment.service.IXhpcRechargeOrderService;
import com.xhpc.payment.service.IXhpcRefundOrderService; import com.xhpc.payment.service.IXhpcRefundOrderService;
import com.xhpc.system.api.model.LoginUser; import com.xhpc.system.api.model.LoginUser;
@ -58,31 +60,22 @@ public class WxPaymentController {
@Autowired @Autowired
private IXhpcRechargeOrderService iXhpcRechargeOrderService; private IXhpcRechargeOrderService iXhpcRechargeOrderService;
@Autowired @Autowired
private XhpcUserAccountStatementMapper xhpcUserAccountStatementMapper; private XhpcUserAccountStatementMapper xhpcUserAccountStatementMapper;
@Autowired @Autowired
private IXhpcRefundOrderService iXhpcRefundOrderService; private IXhpcRefundOrderService iXhpcRefundOrderService;
@Autowired @Autowired
private Environment environment; private Environment environment;
@Autowired @Autowired
private PowerPileService powerPileService; private PowerPileService powerPileService;
@Autowired @Autowired
private TokenService tokenService; private TokenService tokenService;
@Autowired @Autowired
private UserTypeService userTypeService; private UserTypeService userTypeService;
@Autowired
private IXhpcCommonPayment xhpcCommonPayment;
private static final Logger logger = LoggerFactory.getLogger(WxPaymentController.class); private static final Logger logger = LoggerFactory.getLogger(WxPaymentController.class);
private int number;
@PostConstruct
public void init(){
number =1;
}
@PostMapping("/payment") @PostMapping("/payment")
@ApiOperation(value = "微信支付") @ApiOperation(value = "微信支付")
@ -119,6 +112,11 @@ public class WxPaymentController {
if (0.0 == amount1) { if (0.0 == amount1) {
return AjaxResult.error(HttpStatus.NOT_NULL, "充值金额不能为0"); return AjaxResult.error(HttpStatus.NOT_NULL, "充值金额不能为0");
} }
XhpcSettingConfig xhpcSettingConfig = xhpcCommonPayment.getXhpcSettingConfigTenantId(UserTypeUtil.OPERATION_WX_TYPE, tenantId);
if(xhpcSettingConfig ==null){
return AjaxResult.error(HttpStatus.ALREADY_EXISTING, "支付宝充值失败,继续充值请联系客服");
}
//生成充值订单 //生成充值订单
XhpcRechargeOrder xhpcRechargeOrder = iXhpcRechargeOrderService.addRechargeOrder(userId, BigDecimal.valueOf(Double.parseDouble(amount)), "1", orderNumber,userType); XhpcRechargeOrder xhpcRechargeOrder = iXhpcRechargeOrderService.addRechargeOrder(userId, BigDecimal.valueOf(Double.parseDouble(amount)), "1", orderNumber,userType);
//附加数据() //附加数据()
@ -143,7 +141,7 @@ public class WxPaymentController {
BufferedReader in = null; BufferedReader in = null;
StringBuffer result = new StringBuffer(); StringBuffer result = new StringBuffer();
try { try {
URL realUrl = new URL(environment.getProperty("WXPAYUNIFIEDORDER")); URL realUrl = new URL(xhpcSettingConfig.getWxPaymentUrl());
// 打开和URL之间的连接 // 打开和URL之间的连接
URLConnection conn = realUrl.openConnection(); URLConnection conn = realUrl.openConnection();
// 设置通用的请求属性 // 设置通用的请求属性
@ -156,7 +154,7 @@ public class WxPaymentController {
conn.setDoInput(true); conn.setDoInput(true);
// 获取URLConnection对象对应的输出流 // 获取URLConnection对象对应的输出流
out = new PrintWriter(conn.getOutputStream()); out = new PrintWriter(conn.getOutputStream());
out.print(createXMLParam(Fee, attach, tradeType, spbillCreateIp, outTradeNo, body, timeStr, environment.getProperty("SERVERDOMAIN"), environment.getProperty("APPID"), environment.getProperty("MCHID"), environment.getProperty("KEY"), openid)); out.print(createXMLParam(Fee, attach, tradeType, spbillCreateIp, outTradeNo, body, timeStr, xhpcSettingConfig.getWxCallbackUrl(), xhpcSettingConfig.getWxAppId(), xhpcSettingConfig.getWxMchId(), xhpcSettingConfig.getWxMchKey(), openid));
// flush输出流的缓冲 // flush输出流的缓冲
out.flush(); out.flush();
// 定义BufferedReader输入流来读取URL的响应 // 定义BufferedReader输入流来读取URL的响应
@ -185,7 +183,7 @@ public class WxPaymentController {
} }
} }
//app //app
Map<String, String> sign = createSign(result.toString(), Double.parseDouble(amount)); Map<String, String> sign = createSign(result.toString(), Double.parseDouble(amount),xhpcSettingConfig.getWxMchKey());
return AjaxResult.success(sign); return AjaxResult.success(sign);
} }
@ -195,7 +193,7 @@ public class WxPaymentController {
* @param result xml格式字符串 * @param result xml格式字符串
* @return * @return
*/ */
public Map<String, String> createSign(String result, Double amount) { public Map<String, String> createSign(String result, Double amount,String key) {
try { try {
Map<String, String> map = WXPayUtil.xmlToMap(result); Map<String, String> map = WXPayUtil.xmlToMap(result);
String return_code = map.get("return_code"); String return_code = map.get("return_code");
@ -217,7 +215,7 @@ public class WxPaymentController {
map1.put("timestamp", timeStr); map1.put("timestamp", timeStr);
map1.put("sign", map.get("sign")); map1.put("sign", map.get("sign"));
map1.put("url", map.get("code_url")); map1.put("url", map.get("code_url"));
map1.put("key", environment.getProperty("KEY")); map1.put("key", key);
return map1; return map1;
} }
} catch (Exception e) { } catch (Exception e) {

View File

@ -11,7 +11,7 @@ import java.util.List;
@Data @Data
public class MechanismDto { public class MechanismDto {
private Integer id; private String id;
private String label; private String label;

View File

@ -119,7 +119,7 @@ public class IMechanismServiceImpl implements IMechanismService {
for (Map<String, Object> map:list) { for (Map<String, Object> map:list) {
MechanismDto mechanismDto =new MechanismDto(); MechanismDto mechanismDto =new MechanismDto();
String code = map.get("code").toString(); String code = map.get("code").toString();
mechanismDto.setId(Integer.valueOf(code)); mechanismDto.setId("Shen"+code);
mechanismDto.setLabel(map.get("name").toString()); mechanismDto.setLabel(map.get("name").toString());
List<MechanismDto> mechanismCityList =new ArrayList<>(); List<MechanismDto> mechanismCityList =new ArrayList<>();
// //
@ -127,7 +127,7 @@ public class IMechanismServiceImpl implements IMechanismService {
for (Map<String, Object> cityMap:cityList) { for (Map<String, Object> cityMap:cityList) {
MechanismDto mechanismCity =new MechanismDto(); MechanismDto mechanismCity =new MechanismDto();
String codeCity = cityMap.get("code").toString(); String codeCity = cityMap.get("code").toString();
mechanismCity.setId(Integer.valueOf(codeCity)); mechanismCity.setId("Shi"+codeCity);
mechanismCity.setLabel(cityMap.get("name").toString()); mechanismCity.setLabel(cityMap.get("name").toString());
List<MechanismDto> mechanismAreaList =new ArrayList<>(); List<MechanismDto> mechanismAreaList =new ArrayList<>();
// //
@ -135,7 +135,7 @@ public class IMechanismServiceImpl implements IMechanismService {
for (Map<String, Object> areaMap:areaList) { for (Map<String, Object> areaMap:areaList) {
MechanismDto mechanismArea =new MechanismDto(); MechanismDto mechanismArea =new MechanismDto();
String codeArea = areaMap.get("code").toString(); String codeArea = areaMap.get("code").toString();
mechanismArea.setId(Integer.valueOf(codeArea)); mechanismArea.setId("Qu"+codeArea);
mechanismArea.setLabel(areaMap.get("name").toString()); mechanismArea.setLabel(areaMap.get("name").toString());
List<MechanismDto> mechanismOperatorList =new ArrayList<>(); List<MechanismDto> mechanismOperatorList =new ArrayList<>();
//运营商 //运营商
@ -143,7 +143,7 @@ public class IMechanismServiceImpl implements IMechanismService {
for (Map<String, Object> operatorMap:operatorList) { for (Map<String, Object> operatorMap:operatorList) {
MechanismDto mechanismOperator =new MechanismDto(); MechanismDto mechanismOperator =new MechanismDto();
String operatorId = operatorMap.get("operatorId").toString(); String operatorId = operatorMap.get("operatorId").toString();
mechanismOperator.setId(Integer.valueOf(operatorId)); mechanismOperator.setId("Yun"+operatorId);
mechanismOperator.setLabel(operatorMap.get("name").toString()); mechanismOperator.setLabel(operatorMap.get("name").toString());
List<MechanismDto> mechanismdataList =new ArrayList<>(); List<MechanismDto> mechanismdataList =new ArrayList<>();
//场站 //场站
@ -151,7 +151,7 @@ public class IMechanismServiceImpl implements IMechanismService {
for (Map<String, Object> dataMap:dataList) { for (Map<String, Object> dataMap:dataList) {
MechanismDto mechanismData =new MechanismDto(); MechanismDto mechanismData =new MechanismDto();
String codeData = dataMap.get("chargingStationId").toString(); String codeData = dataMap.get("chargingStationId").toString();
mechanismData.setId(Integer.valueOf(codeData)); mechanismData.setId(codeData);
mechanismData.setLabel(dataMap.get("name").toString()); mechanismData.setLabel(dataMap.get("name").toString());
mechanismdataList.add(mechanismData); mechanismdataList.add(mechanismData);
} }
@ -181,7 +181,7 @@ public class IMechanismServiceImpl implements IMechanismService {
for (Map<String, Object> operatorMap:operatorList) { for (Map<String, Object> operatorMap:operatorList) {
MechanismDto mechanismOperator =new MechanismDto(); MechanismDto mechanismOperator =new MechanismDto();
String operatorId = operatorMap.get("operatorId").toString(); String operatorId = operatorMap.get("operatorId").toString();
mechanismOperator.setId(Integer.valueOf(operatorId)); mechanismOperator.setId("Yun"+operatorId);
mechanismOperator.setLabel(operatorMap.get("name").toString()); mechanismOperator.setLabel(operatorMap.get("name").toString());
List<MechanismDto> mechanismdataList =new ArrayList<>(); List<MechanismDto> mechanismdataList =new ArrayList<>();
//场站 //场站
@ -189,7 +189,7 @@ public class IMechanismServiceImpl implements IMechanismService {
for (Map<String, Object> dataMap:dataList) { for (Map<String, Object> dataMap:dataList) {
MechanismDto mechanismData =new MechanismDto(); MechanismDto mechanismData =new MechanismDto();
String codeData = dataMap.get("chargingStationId").toString(); String codeData = dataMap.get("chargingStationId").toString();
mechanismData.setId(Integer.valueOf(codeData)); mechanismData.setId(codeData);
mechanismData.setLabel(dataMap.get("name").toString()); mechanismData.setLabel(dataMap.get("name").toString());
mechanismdataList.add(mechanismData); mechanismdataList.add(mechanismData);
} }
@ -214,7 +214,7 @@ public class IMechanismServiceImpl implements IMechanismService {
for (Map<String, Object> operatorMap:operatorList) { for (Map<String, Object> operatorMap:operatorList) {
MechanismDto mechanismOperator =new MechanismDto(); MechanismDto mechanismOperator =new MechanismDto();
String operatorId = operatorMap.get("operatorId").toString(); String operatorId = operatorMap.get("operatorId").toString();
mechanismOperator.setId(Integer.valueOf(operatorId)); mechanismOperator.setId("Yun"+operatorId);
mechanismOperator.setLabel(operatorMap.get("name").toString()); mechanismOperator.setLabel(operatorMap.get("name").toString());
List<MechanismDto> mechanismdataList =new ArrayList<>(); List<MechanismDto> mechanismdataList =new ArrayList<>();
// //
@ -222,7 +222,7 @@ public class IMechanismServiceImpl implements IMechanismService {
for (Map<String, Object> map:list) { for (Map<String, Object> map:list) {
MechanismDto mechanismDto =new MechanismDto(); MechanismDto mechanismDto =new MechanismDto();
String code = map.get("code").toString(); String code = map.get("code").toString();
mechanismDto.setId(Integer.valueOf(code)); mechanismDto.setId("Shen"+code);
mechanismDto.setLabel(map.get("name").toString()); mechanismDto.setLabel(map.get("name").toString());
List<MechanismDto> mechanismCityList =new ArrayList<>(); List<MechanismDto> mechanismCityList =new ArrayList<>();
// //
@ -230,7 +230,7 @@ public class IMechanismServiceImpl implements IMechanismService {
for (Map<String, Object> cityMap:cityList) { for (Map<String, Object> cityMap:cityList) {
MechanismDto mechanismCity =new MechanismDto(); MechanismDto mechanismCity =new MechanismDto();
String codeCity = cityMap.get("code").toString(); String codeCity = cityMap.get("code").toString();
mechanismCity.setId(Integer.valueOf(codeCity)); mechanismCity.setId("Shi"+codeCity);
mechanismCity.setLabel(cityMap.get("name").toString()); mechanismCity.setLabel(cityMap.get("name").toString());
List<MechanismDto> mechanismAreaList =new ArrayList<>(); List<MechanismDto> mechanismAreaList =new ArrayList<>();
// //
@ -238,7 +238,7 @@ public class IMechanismServiceImpl implements IMechanismService {
for (Map<String, Object> areaMap:areaList) { for (Map<String, Object> areaMap:areaList) {
MechanismDto mechanismArea =new MechanismDto(); MechanismDto mechanismArea =new MechanismDto();
String codeArea = areaMap.get("code").toString(); String codeArea = areaMap.get("code").toString();
mechanismArea.setId(Integer.valueOf(codeArea)); mechanismArea.setId("Qu"+codeArea);
mechanismArea.setLabel(areaMap.get("name").toString()); mechanismArea.setLabel(areaMap.get("name").toString());
List<MechanismDto> mechanismOperatorList =new ArrayList<>(); List<MechanismDto> mechanismOperatorList =new ArrayList<>();
//场站 //场站
@ -246,7 +246,7 @@ public class IMechanismServiceImpl implements IMechanismService {
for (Map<String, Object> dataMap:dataList) { for (Map<String, Object> dataMap:dataList) {
MechanismDto mechanismData =new MechanismDto(); MechanismDto mechanismData =new MechanismDto();
String codeData = dataMap.get("chargingStationId").toString(); String codeData = dataMap.get("chargingStationId").toString();
mechanismData.setId(Integer.valueOf(codeData)); mechanismData.setId(codeData);
mechanismData.setLabel(dataMap.get("name").toString()); mechanismData.setLabel(dataMap.get("name").toString());
mechanismOperatorList.add(mechanismData); mechanismOperatorList.add(mechanismData);
} }