小七折扣支付

master
PC-202302260912\Administrator 2023-07-26 11:19:36 +08:00
parent f1e959a854
commit 87c3e46e1b
5 changed files with 45 additions and 148 deletions

View File

@ -12,6 +12,7 @@ import com.jmfy.util.JsonUtil;
import org.apache.commons.lang.ArrayUtils; import org.apache.commons.lang.ArrayUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import javax.annotation.Resource; import javax.annotation.Resource;
@ -31,12 +32,13 @@ public class PayLogic {
private static final Logger LOGGER = LoggerFactory.getLogger(PayLogic.class); private static final Logger LOGGER = LoggerFactory.getLogger(PayLogic.class);
@Resource @Resource
private CUserDao cuserDao; private static CUserDao cuserDao;
@Autowired
private PayLogic() { public PayLogic(CUserDao cuserDao) {
this.cuserDao = cuserDao;
} }
public String initOrder(String collBackInfo, String orderId, String amount, Date time, String openId, PaySdkEnum sdk){ public static String initOrder(String collBackInfo, String orderId, String amount, Date time, String openId, PaySdkEnum sdk){
return initOrder(collBackInfo,orderId,amount,time,openId,sdk,""); return initOrder(collBackInfo,orderId,amount,time,openId,sdk,"");
} }
@ -50,7 +52,7 @@ public class PayLogic {
* @param sdk sdk * @param sdk sdk
* @return * @return
*/ */
public String initOrder(String collBackInfo, String orderId, String amount, Date time, String openId, PaySdkEnum sdk, String ext){ public static String initOrder(String collBackInfo, String orderId, String amount, Date time, String openId, PaySdkEnum sdk, String ext){
try { try {
// 角色id_物品id_ccId_平台 // 角色id_物品id_ccId_平台
String[] collback = collBackInfo.split("_"); String[] collback = collBackInfo.split("_");

View File

@ -0,0 +1,20 @@
package com.jmfy.controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest;
/**
*
*/
@RestController
public class XiaoqiDiscountRechargeController {
private static final String PAYKEY = "fd0f6c0bc2e5042096cb26c6c718c772";
@RequestMapping(value = "/Web/xiaoqiDiscountCallback")
public String youguCallback(HttpServletRequest request) throws Exception {
return YouGuRechargeController.callback(request, PAYKEY);
}
}

View File

@ -1,6 +1,5 @@
package com.jmfy.controller; package com.jmfy.controller;
import com.google.gson.Gson;
import com.jmfy.paramBean.PaySdkEnum; import com.jmfy.paramBean.PaySdkEnum;
import com.jmfy.util.JsonUtil; import com.jmfy.util.JsonUtil;
import com.jmfy.util.MD5Util; import com.jmfy.util.MD5Util;
@ -10,8 +9,8 @@ import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@ -22,15 +21,23 @@ import java.util.Map;
@RestController @RestController
public class YouGuRechargeController { public class YouGuRechargeController {
@Resource
private PayLogic payLogic;
private static final String PAYKEY = "fda6e5e13e75285dd0c8e8636a85704b"; private static final String PAYKEY = "fda6e5e13e75285dd0c8e8636a85704b";
private static final Logger LOGGER = LoggerFactory.getLogger(YouGuRechargeController.class); private static final Logger LOGGER = LoggerFactory.getLogger(YouGuRechargeController.class);
@RequestMapping(value = "/Web/youguCallback") @RequestMapping(value = "/Web/youguCallback")
public String youguCallback(HttpServletRequest request) throws Exception { public String youguCallback(HttpServletRequest request) throws Exception {
return callback(request, PAYKEY);
}
/**
*
* @param request
* @param payKey
* @return
* @throws IOException
*/
public static String callback(HttpServletRequest request, String payKey) throws IOException {
JSONObject jsonObject = new JSONObject(); JSONObject jsonObject = new JSONObject();
jsonObject.put("errno","1"); jsonObject.put("errno","1");
@ -40,7 +47,7 @@ public class YouGuRechargeController {
jsonObject.put("errmsg","youguCallback data is null"); jsonObject.put("errmsg","youguCallback data is null");
return jsonObject.toString(); return jsonObject.toString();
} }
boolean sign = verifySign(parameterMap); boolean sign = verifySign(parameterMap, payKey);
if (!sign) { if (!sign) {
LOGGER.info("悠谷---》sign error"); LOGGER.info("悠谷---》sign error");
jsonObject.put("errmsg","sign error"); jsonObject.put("errmsg","sign error");
@ -51,7 +58,7 @@ public class YouGuRechargeController {
int amount = Integer.parseInt(parameterMap.get("amount"))*100; // 充值金额(单位:元)(需要换算成分) int amount = Integer.parseInt(parameterMap.get("amount"))*100; // 充值金额(单位:元)(需要换算成分)
String gameExt = request.getParameter("extinfo"); //透传参数如CP下单有值提交则会原样回传不得超过255个字符 String gameExt = request.getParameter("extinfo"); //透传参数如CP下单有值提交则会原样回传不得超过255个字符
String[] callback = gameExt.split("_"); String[] callback = gameExt.split("_");
String result = payLogic.initOrder(gameExt, orderno, String.valueOf(amount), new Date(), callback[0], PaySdkEnum.YOUGU); String result = PayLogic.initOrder(gameExt, orderno, String.valueOf(amount), new Date(), callback[0], PaySdkEnum.YOUGU);
jsonObject.put("errmsg",result); jsonObject.put("errmsg",result);
if (result.equals("SUCCESS")){ if (result.equals("SUCCESS")){
jsonObject.put("errno","0"); jsonObject.put("errno","0");
@ -60,13 +67,12 @@ public class YouGuRechargeController {
return jsonObject.toString(); return jsonObject.toString();
} }
/** /**
* sign * sign
* @param map * @param map
* @return * @return
*/ */
private boolean verifySign(Map<String, String> map) { public static boolean verifySign(Map<String, String> map, String payKey) {
String status = map.get("status"); // 状态1 成功2 失败)(目前支付失败不通知) String status = map.get("status"); // 状态1 成功2 失败)(目前支付失败不通知)
if (status == null || status.isEmpty() || !"1".equals(status)) { if (status == null || status.isEmpty() || !"1".equals(status)) {
LOGGER.error("yougu Callback orderStatus={}", status); LOGGER.error("yougu Callback orderStatus={}", status);
@ -80,7 +86,7 @@ public class YouGuRechargeController {
String nonce = map.get("nonce"); //签名时间戳(由 51sfsy 服务端获取当前时间戳,用于生成签名) String nonce = map.get("nonce"); //签名时间戳(由 51sfsy 服务端获取当前时间戳,用于生成签名)
String token = map.get("token"); //签名(规则见下 String token = map.get("token"); //签名(规则见下
String mySign = MD5Util.encrypByMd5(sid + uid + orderno + amount + gameExt + nonce + PAYKEY); String mySign = MD5Util.encrypByMd5(sid + uid + orderno + amount + gameExt + nonce + payKey);
if (!mySign.equals(token)) { if (!mySign.equals(token)) {
LOGGER.error("yougu Callback==>roleUid={},sin derify fail, my sign={} sign={}", gameExt, mySign, token); LOGGER.error("yougu Callback==>roleUid={},sin derify fail, my sign={} sign={}", gameExt, mySign, token);
return false; return false;

View File

@ -21,69 +21,10 @@ import java.util.Map;
@RestController @RestController
public class YouGuXQRechargeController { public class YouGuXQRechargeController {
@Resource
private PayLogic payLogic;
private static final String PAYKEY = "afc0f968ddbdb0d1de3e59ddb01ad892"; private static final String PAYKEY = "afc0f968ddbdb0d1de3e59ddb01ad892";
private static final Logger LOGGER = LoggerFactory.getLogger(YouGuXQRechargeController.class);
@RequestMapping(value = "/Web/youguXQCallback") @RequestMapping(value = "/Web/youguXQCallback")
public String youguCallback(HttpServletRequest request) throws Exception { public String youguCallback(HttpServletRequest request) throws Exception {
JSONObject jsonObject = new JSONObject(); return YouGuRechargeController.callback(request, PAYKEY);
jsonObject.put("errno","1");
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap2(request);
if (parameterMap.isEmpty()) {
LOGGER.info("悠谷---》youguXQCallback data is null");
jsonObject.put("errmsg","youguXQCallback data is null");
return jsonObject.toString();
}
boolean sign = verifySign(parameterMap);
if (!sign) {
LOGGER.info("悠谷---》sign error");
jsonObject.put("errmsg","sign error");
return jsonObject.toString();
}
String orderno = parameterMap.get("orderno"); // 51sfsy 支付订单号(唯一
int amount = Integer.parseInt(parameterMap.get("amount"))*100; // 充值金额(单位:元)(需要换算成分)
String gameExt = request.getParameter("extinfo"); //透传参数如CP下单有值提交则会原样回传不得超过255个字符
String[] callback = gameExt.split("_");
String result = payLogic.initOrder(gameExt, orderno, String.valueOf(amount), new Date(), callback[0], PaySdkEnum.YOUGU);
jsonObject.put("errmsg",result);
if (result.equals("SUCCESS")){
jsonObject.put("errno","0");
return jsonObject.toString();
}
return jsonObject.toString();
}
/**
* sign
* @param map
* @return
*/
private boolean verifySign(Map<String, String> map) {
String status = map.get("status"); // 状态1 成功2 失败)(目前支付失败不通知)
if (status == null || status.isEmpty() || !"1".equals(status)) {
LOGGER.error("youguXQCallback orderStatus={}", status);
return false;
}
String sid = map.get("sid"); //游戏区服标识
String uid = map.get("uid"); //51sfsy 用户 ID
String orderno = map.get("orderno"); // 51sfsy 支付订单号(唯一
String amount = map.get("amount"); // 充值金额(单位:元)
String gameExt = map.get("extinfo"); //透传参数如CP下单有值提交则会原样回传不得超过255个字符
String nonce = map.get("nonce"); //签名时间戳(由 51sfsy 服务端获取当前时间戳,用于生成签名)
String token = map.get("token"); //签名(规则见下
String mySign = MD5Util.encrypByMd5(sid + uid + orderno + amount + gameExt + nonce + PAYKEY);
if (!mySign.equals(token)) {
LOGGER.error("youguXQCallback==>roleUid={},sin derify fail, my sign={} sign={}", gameExt, mySign, token);
return false;
}
return true;
} }
} }

View File

@ -1,90 +1,18 @@
package com.jmfy.controller; package com.jmfy.controller;
import com.jmfy.paramBean.PaySdkEnum;
import com.jmfy.util.JsonUtil;
import com.jmfy.util.MD5Util;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/** /**
* *
*/ */
@RestController @RestController
public class YouguDiscountRechargeController { public class YouguDiscountRechargeController {
@Resource
private PayLogic payLogic;
private static final String PAYKEY = "ceff390cc5be9960dcc90c62dd9fe64b"; private static final String PAYKEY = "ceff390cc5be9960dcc90c62dd9fe64b";
private static final Logger LOGGER = LoggerFactory.getLogger(YouguDiscountRechargeController.class);
@RequestMapping(value = "/Web/youguDiscountCallback") @RequestMapping(value = "/Web/youguDiscountCallback")
public String youguCallback(HttpServletRequest request) throws Exception { public String youguCallback(HttpServletRequest request) throws Exception {
JSONObject jsonObject = new JSONObject(); return YouGuRechargeController.callback(request, PAYKEY);
jsonObject.put("errno","1");
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap2(request);
if (parameterMap.isEmpty()) {
LOGGER.error("悠谷---》youguXQCallback data is null");
jsonObject.put("errmsg","youguXQCallback data is null");
return jsonObject.toString();
}
boolean sign = verifySign(parameterMap);
if (!sign) {
LOGGER.error("悠谷---》sign error");
jsonObject.put("errmsg","sign error");
return jsonObject.toString();
}
LOGGER.info("悠谷这口服回调参数:{}",parameterMap);
String orderno = parameterMap.get("orderno"); // 51sfsy 支付订单号(唯一
int amount = Integer.parseInt(parameterMap.get("amount"))*100; // 充值金额(单位:元)(需要换算成分)
String gameExt = request.getParameter("extinfo"); //透传参数如CP下单有值提交则会原样回传不得超过255个字符
String[] callback = gameExt.split("_");
String result = payLogic.initOrder(gameExt, orderno, String.valueOf(amount), new Date(), callback[0], PaySdkEnum.YOUGU);
jsonObject.put("errmsg",result);
if (result.equals("SUCCESS")){
jsonObject.put("errno","0");
return jsonObject.toString();
}
return jsonObject.toString();
}
/**
* sign
* @param map
* @return
*/
private boolean verifySign(Map<String, String> map) {
String status = map.get("status"); // 状态1 成功2 失败)(目前支付失败不通知)
if (status == null || status.isEmpty() || !"1".equals(status)) {
LOGGER.error("youguXQCallback orderStatus={}", status);
return false;
}
String sid = map.get("sid"); //游戏区服标识
String uid = map.get("uid"); //51sfsy 用户 ID
String orderno = map.get("orderno"); // 51sfsy 支付订单号(唯一
String amount = map.get("amount"); // 充值金额(单位:元)
String gameExt = map.get("extinfo"); //透传参数如CP下单有值提交则会原样回传不得超过255个字符
String nonce = map.get("nonce"); //签名时间戳(由 51sfsy 服务端获取当前时间戳,用于生成签名)
String token = map.get("token"); //签名(规则见下
String mySign = MD5Util.encrypByMd5(sid + uid + orderno + amount + gameExt + nonce + PAYKEY);
if (!mySign.equals(token)) {
LOGGER.error("youguXQCallback==>roleUid={},sin derify fail, my sign={} sign={}", gameExt, mySign, token);
return false;
}
return true;
} }
} }