generated from root/miduo_server
悠谷支付
parent
e263a479b3
commit
6aa315d93b
|
@ -1,14 +1,9 @@
|
||||||
package com.jmfy.controller;
|
package com.jmfy.controller;
|
||||||
|
|
||||||
import com.jmfy.dto.CPayOrder;
|
import com.jmfy.paramBean.PaySdkEnum;
|
||||||
import com.jmfy.dto.CUserDao;
|
|
||||||
import com.jmfy.dto.CUserInfo;
|
|
||||||
import com.jmfy.thrift.idl.RPCRequestIFace;
|
|
||||||
import com.jmfy.thrift.idl.Result;
|
|
||||||
import com.jmfy.thrift.pool.ClientAdapterPo;
|
|
||||||
import com.jmfy.thrift.pool.ServiceKey;
|
|
||||||
import com.jmfy.util.JsonUtil;
|
import com.jmfy.util.JsonUtil;
|
||||||
import com.jmfy.util.MD5Util;
|
import com.jmfy.util.MD5Util;
|
||||||
|
import org.json.JSONObject;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.web.bind.annotation.RequestMapping;
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
@ -16,10 +11,9 @@ import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.text.DateFormat;
|
|
||||||
import java.text.SimpleDateFormat;
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 悠谷游戏
|
* 悠谷游戏
|
||||||
|
@ -28,7 +22,7 @@ import java.util.HashMap;
|
||||||
public class YouGuRechargeController {
|
public class YouGuRechargeController {
|
||||||
|
|
||||||
@Resource
|
@Resource
|
||||||
private CUserDao cuserDao;
|
private PayLogic payLogic;
|
||||||
|
|
||||||
private static final String PAYKEY = "fda6e5e13e75285dd0c8e8636a85704b";
|
private static final String PAYKEY = "fda6e5e13e75285dd0c8e8636a85704b";
|
||||||
|
|
||||||
|
@ -36,87 +30,62 @@ public class YouGuRechargeController {
|
||||||
|
|
||||||
@RequestMapping(value = "/Web/youguCallback")
|
@RequestMapping(value = "/Web/youguCallback")
|
||||||
public String youguCallback(HttpServletRequest request) throws Exception {
|
public String youguCallback(HttpServletRequest request) throws Exception {
|
||||||
|
JSONObject jsonObject = new JSONObject();
|
||||||
|
jsonObject.put("errno","1");
|
||||||
|
|
||||||
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap2(request);
|
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap2(request);
|
||||||
if (parameterMap.isEmpty()) {
|
if (parameterMap.isEmpty()) {
|
||||||
LOGGER.info("ktGameCallback data is null");
|
LOGGER.info("悠谷---》youguCallback data is null");
|
||||||
return "FAIL";
|
jsonObject.put("errmsg","youguCallback data is null");
|
||||||
|
return jsonObject.toString();
|
||||||
}
|
}
|
||||||
String status = request.getParameter("status"); // 状态(1 成功,2 失败)(目前支付失败不通知)
|
boolean sign = verifySign(parameterMap);
|
||||||
if (status == null || status.isEmpty() || !"1".equals(status)) {
|
if (!sign) {
|
||||||
LOGGER.info("youguCallback orderStatus={}", status);
|
LOGGER.info("悠谷---》sign error");
|
||||||
return "FAIL";
|
jsonObject.put("errmsg","sign error");
|
||||||
|
return jsonObject.toString();
|
||||||
}
|
}
|
||||||
String sid = request.getParameter("sid"); //游戏区服标识
|
|
||||||
String uid = request.getParameter("uid"); //51sfsy 用户 ID
|
|
||||||
String orderno = parameterMap.get("orderno"); // 51sfsy 支付订单号(唯一
|
String orderno = parameterMap.get("orderno"); // 51sfsy 支付订单号(唯一
|
||||||
String amount = parameterMap.get("amount"); // 充值金额(单位:元)
|
String amount = parameterMap.get("amount"); // 充值金额(单位:元)
|
||||||
String gameExt = request.getParameter("extinfo"); //透传参数,如CP下单有值提交,则会原样回传,不得超过255个字符
|
String gameExt = request.getParameter("extinfo"); //透传参数,如CP下单有值提交,则会原样回传,不得超过255个字符
|
||||||
String nonce = request.getParameter("nonce"); //签名时间戳(由 51sfsy 服务端获取当前时间戳,用于生成签名)
|
String[] callback = gameExt.split("_");
|
||||||
String token = request.getParameter("token"); //签名(规则见下
|
String result = payLogic.initOrder(gameExt, orderno, 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("yougu Callback 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"); //签名(规则见下
|
||||||
|
|
||||||
StringBuilder sbKey = new StringBuilder();
|
StringBuilder sbKey = new StringBuilder();
|
||||||
sbKey.append(sid).append(uid).append(orderno).append(amount).append(gameExt).append(nonce).append(PAYKEY);
|
sbKey.append(sid).append(uid).append(orderno).append(amount).append(gameExt).append(nonce).append(PAYKEY);
|
||||||
String mySign = MD5Util.encrypByMd5(sbKey.toString());
|
String mySign = MD5Util.encrypByMd5(sbKey.toString());
|
||||||
if (!mySign.equals(token)) {
|
if (!mySign.equals(token)) {
|
||||||
LOGGER.info("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 "FAIL";
|
return false;
|
||||||
}
|
}
|
||||||
// gameExtArr: userid_goodsid_ccid_platform
|
return true;
|
||||||
CUserInfo cUserInfo = cuserDao.findUserByOpenIdAndUidInfo(uid, sid);
|
|
||||||
if (cUserInfo == null) {
|
|
||||||
LOGGER.info("该用户无此角色 openid={} serverID={}", uid, sid);
|
|
||||||
return "FAIL";
|
|
||||||
}
|
|
||||||
CPayOrder cPayOrder = cuserDao.getCpayOrderByOrderId(orderno);
|
|
||||||
String response = "success";
|
|
||||||
if (cPayOrder != null) {
|
|
||||||
LOGGER.info("callback==>creditId={},uId={} orderId is exit!!!", cUserInfo.getId(), cUserInfo.getOpenId());
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
String userAddress = cuserDao.findUserAddress(cUserInfo.getId());
|
|
||||||
if (userAddress == null || userAddress.isEmpty()) {
|
|
||||||
LOGGER.info("callback==>userAddress={} openId={} uid={}", userAddress, uid, cUserInfo.getId());
|
|
||||||
return "FAIL";
|
|
||||||
}
|
|
||||||
// gameExtArr: userid_goodsid_ccid_platform
|
|
||||||
String[] gameExtArr = gameExt.split("_");
|
|
||||||
DateFormat dateTimeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
|
||||||
String date = dateTimeformat.format(new Date());
|
|
||||||
cPayOrder = new CPayOrder();
|
|
||||||
cPayOrder.setOrderId(orderno);
|
|
||||||
cPayOrder.setServerId(cUserInfo.getServerid());
|
|
||||||
cPayOrder.setDelivery_time(date);
|
|
||||||
cPayOrder.setAmount(amount);
|
|
||||||
cPayOrder.setGoodsId(gameExtArr[1]);
|
|
||||||
cPayOrder.setCc_id(gameExtArr[2]);
|
|
||||||
cPayOrder.setPaySdk("YG");
|
|
||||||
cPayOrder.setPlatform(gameExtArr[3]);
|
|
||||||
cPayOrder.setUserId(Integer.toString(cUserInfo.getId()));
|
|
||||||
Result result = null;
|
|
||||||
String[] split = userAddress.split(":");
|
|
||||||
String ip = split[0];
|
|
||||||
String port = split[1];
|
|
||||||
LOGGER.info("RPC address uid={}--> IP : {} PORT : {}", cUserInfo.getId(), ip, port);
|
|
||||||
ClientAdapterPo<RPCRequestIFace.Client> rPCClient = null;
|
|
||||||
String serviceKey = JsonUtil.getServiceKey(ServiceKey.RPCCore, ip, port);
|
|
||||||
try {
|
|
||||||
rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
|
|
||||||
result = rPCClient.getClient().deliveryRecharge(cUserInfo.getId(), gameExtArr[1], cUserInfo.getOpenId(), orderno, Long.parseLong(nonce) * 1000, (int) (Float.parseFloat(amount)));
|
|
||||||
} catch (Exception e) {
|
|
||||||
LOGGER.info("callback=>", e);
|
|
||||||
return "FAIL";
|
|
||||||
} finally {
|
|
||||||
if (rPCClient != null) {
|
|
||||||
rPCClient.returnObject(serviceKey);
|
|
||||||
} else {
|
|
||||||
LOGGER.info("callback=> rPCClient is null ");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (result != null && result.getResultCode() == 1) {
|
|
||||||
LOGGER.info(" callback==>RPC result : ResultCode : " + result.getResultCode() + "; ResultMsg : " + result.getResultMsg());
|
|
||||||
cuserDao.addCpayOrder(cPayOrder);
|
|
||||||
return response;
|
|
||||||
}
|
|
||||||
return "FAIL";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ public enum PaySdkEnum {
|
||||||
HANFAN(9,"HAOFAN"),
|
HANFAN(9,"HAOFAN"),
|
||||||
FENGTIIOS(10,"FENGTIIOS"),
|
FENGTIIOS(10,"FENGTIIOS"),
|
||||||
ANJIU(11, "ANJIU"),
|
ANJIU(11, "ANJIU"),
|
||||||
|
YOUGU(12,"YOUGU")
|
||||||
;
|
;
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
|
|
Loading…
Reference in New Issue