动游sdk

master
mengchengzhen 2021-07-22 10:09:43 +08:00
parent 16072138ab
commit c7332e70c3
3 changed files with 318 additions and 0 deletions

View File

@ -0,0 +1,207 @@
package com.jmfy.controller;
import com.google.gson.JsonObject;
import com.jmfy.dto.CPayOrder;
import com.jmfy.dto.CUserDao;
import com.jmfy.dto.CUserInfo;
import com.jmfy.paramBean.DyParamBean;
import com.jmfy.paramBean.PaySdkEnum;
import com.jmfy.paramBean.YxylParamBean;
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.MD5Util;
import org.apache.commons.lang.ArrayUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
@RestController
public class DyRechargeController {
private static String PAYKEY = "1f6de741eae348f09851c7c433a3700f";
private static final Logger LOGGER = LoggerFactory.getLogger(DyRechargeController.class);
@Resource
private CUserDao cuserDao;
@RequestMapping(value = "/DyCallback")
public String DyCallback(HttpServletRequest request) throws Exception {
return process(request).toString();
}
private JsonObject process(HttpServletRequest request) throws IOException {
LOGGER.info("-------------DyCallback------------");
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap2(request);
JsonObject jsonObject = new JsonObject();
if (parameterMap.isEmpty()) {
LOGGER.info("data is null");
jsonObject.addProperty("code","-19");
jsonObject.addProperty("msg","fail");
return jsonObject;
}
try {
DyParamBean paramBean = getData(parameterMap);
String mySign = getMySign(paramBean);
if (!paramBean.getSign().equals(mySign)) {
LOGGER.info("sign err");
jsonObject.addProperty("code","-17");
jsonObject.addProperty("msg","fail");
return jsonObject;
}
insertOrder(paramBean);
}catch (Exception e) {
e.printStackTrace();
LOGGER.info("callback==>err " + e.toString());
jsonObject.addProperty("code","-19");
jsonObject.addProperty("msg","fail");
return jsonObject;
}
return jsonObject;
}
private JsonObject insertOrder(DyParamBean data) {
String callbackInfo = data.getExtension();
String orderNo = data.getGameorder();
String amount = data.getTotal();
Date time = new Date(System.currentTimeMillis());
return initOrder(callbackInfo,orderNo,amount,time,data.getRoleid(), PaySdkEnum.DY);
}
private static String getMySign(DyParamBean paramBean){
String paramStr = "extension="+paramBean.getExtension()
+"&gameorder="+paramBean.getGameorder()
+"&orderid="+paramBean.getOrderid()
+"&productid="+paramBean.getProductid()
+"&roleid="+paramBean.getRoleid()
+"&serverid="+paramBean.getServerid()
+"&time="+paramBean.getTime()
+"&total="+paramBean.getTotal()
+"&user="+paramBean.getUser()
+PAYKEY;
String sign = MD5Util.encrypByMd5(paramStr);
LOGGER.info("加密前字符串:{}",paramStr);
LOGGER.info("加密后得:{}",sign);
return sign;
}
private DyParamBean getData(HashMap<String, String> parameterMap) {
DyParamBean paramBean = new DyParamBean();
paramBean.setUser(parameterMap.getOrDefault("user",""));
paramBean.setOrderid(parameterMap.getOrDefault("orderid",""));
paramBean.setGameorder(parameterMap.getOrDefault("gameorder",""));
paramBean.setProductid(parameterMap.getOrDefault("productid",""));
paramBean.setTotal(parameterMap.getOrDefault("total",""));
paramBean.setRoleid(parameterMap.getOrDefault("roleid",""));
paramBean.setServerid(parameterMap.getOrDefault("serverid",""));
paramBean.setTime(parameterMap.getOrDefault("time",""));
paramBean.setExtension(parameterMap.getOrDefault("extension",""));
paramBean.setSign(parameterMap.getOrDefault("sign",""));
LOGGER.info(paramBean.toString());
return paramBean;
}
public JsonObject initOrder(String collBackInfo, String orderId, String amount, Date time, String openId, PaySdkEnum sdk){
JsonObject jsonObject = new JsonObject();
try {
// 角色id_物品id_ccId_平台
String[] collback = collBackInfo.split("_");
LOGGER.info("支付透传参数,分割前:{},分割后:{},长度:{},支付:{}",collBackInfo, ArrayUtils.toString(collback,","),collback.length,sdk.getName());
String uid = collback.length > 0 ? collback[0] : "0";
String goodsId = collback.length > 1 ? collback[1] : "0";
String ccId = collback.length > 2 ? collback[2] : "0";
String platform = collback.length > 3 ? collback[3] : "ANDROID";
CUserInfo cUserInfo = cuserDao.findUserInfo(Integer.valueOf(uid));
if (cUserInfo == null) {
LOGGER.info("该用户无此角色" + uid);
jsonObject.addProperty("code","-11");
jsonObject.addProperty("msg","fail");
return jsonObject;
}
CPayOrder cPayOrder = cuserDao.getCpayOrderByOrderId(orderId);
if (cPayOrder != null) {
LOGGER.info("callback==>creditId={},uId={} orderId is exit!!!", cUserInfo.getId(), cUserInfo.getOpenId());
jsonObject.addProperty("code","-12");
jsonObject.addProperty("msg","fail");
return jsonObject;
} else {
DateFormat dateTimeformat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String date = dateTimeformat.format(time);
cPayOrder = new CPayOrder();
cPayOrder.setOrderId(orderId);
cPayOrder.setServerId(cUserInfo.getServerid());
cPayOrder.setDelivery_time(date);
cPayOrder.setUserId(uid);
cPayOrder.setAmount(amount);
cPayOrder.setGoodsId(goodsId);
cPayOrder.setCc_id(ccId);
cPayOrder.setPaySdk(sdk.getName());
cPayOrder.setPlatform(platform);
Result result = null;
String userAddress = cuserDao.findUserAddress(cUserInfo.getId());
if (userAddress != null) {
LOGGER.info("callback==>userAddress={} ", userAddress);
String[] split = userAddress.split(":");
String ip = split[0];
String port = split[1];
LOGGER.info("RPC address --> IP : " + ip + "; PORT : " + port);
ClientAdapterPo<RPCRequestIFace.Client> rPCClient = null;
String serviceKey = JsonUtil.getServiceKey(ServiceKey.RPCCore, ip, port);
LOGGER.info("serviceKey : " + serviceKey);
try {
rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
result = rPCClient.getClient().deliveryRecharge(cUserInfo.getId(), goodsId, openId, orderId, 0, (int)Double.parseDouble(amount));
} catch (Exception e) {
LOGGER.info("callback=>", e);
} finally {
if (rPCClient != null) {
rPCClient.returnObject(serviceKey);
} else {
LOGGER.info("callback=> rPCClient is null ");
}
}
} else {
LOGGER.info("not get the user url,the openID={} ", uid);
jsonObject.addProperty("code","-11");
jsonObject.addProperty("msg","fail");
return jsonObject;
}
if (result != null && result.getResultCode() == 1) {
LOGGER.info(" callback==>RPC result : ResultCode : " + result.getResultCode() + "; ResultMsg : " + result.getResultMsg());
cuserDao.addCpayOrder(cPayOrder);
} else {
System.out.println("测试代码");
jsonObject.addProperty("code","-18");
jsonObject.addProperty("msg","fail");
return jsonObject;
}
}
} catch (Exception e) {
e.printStackTrace();
LOGGER.info("callback==>err " + e.toString());
jsonObject.addProperty("code","-18");
jsonObject.addProperty("msg","fail");
return jsonObject;
}
jsonObject.addProperty("code","0");
jsonObject.addProperty("msg","success");
return jsonObject;
}
}

View File

@ -0,0 +1,110 @@
package com.jmfy.paramBean;
public class DyParamBean {
private String user;
private String orderid;
private String gameorder;
private String productid;
private String total;
private String roleid;
private String serverid;
private String time;
private String extension;
private String sign;
public String getUser() {
return user;
}
public void setUser(String user) {
this.user = user;
}
public String getOrderid() {
return orderid;
}
public void setOrderid(String orderid) {
this.orderid = orderid;
}
public String getGameorder() {
return gameorder;
}
public void setGameorder(String gameorder) {
this.gameorder = gameorder;
}
public String getProductid() {
return productid;
}
public void setProductid(String productid) {
this.productid = productid;
}
public String getTotal() {
return total;
}
public void setTotal(String total) {
this.total = total;
}
public String getRoleid() {
return roleid;
}
public void setRoleid(String roleid) {
this.roleid = roleid;
}
public String getServerid() {
return serverid;
}
public void setServerid(String serverid) {
this.serverid = serverid;
}
public String getTime() {
return time;
}
public void setTime(String time) {
this.time = time;
}
public String getExtension() {
return extension;
}
public void setExtension(String extension) {
this.extension = extension;
}
public String getSign() {
return sign;
}
public void setSign(String sign) {
this.sign = sign;
}
@Override
public String toString() {
return "DyParamBean{" +
"user='" + user + '\'' +
", orderid='" + orderid + '\'' +
", gameorder='" + gameorder + '\'' +
", productid='" + productid + '\'' +
", total='" + total + '\'' +
", roleid='" + roleid + '\'' +
", serverid='" + serverid + '\'' +
", time='" + time + '\'' +
", extension='" + extension + '\'' +
", sign='" + sign + '\'' +
'}';
}
}

View File

@ -13,6 +13,7 @@ public enum PaySdkEnum {
CH(3,"草花"),
QUICK(4,"QUICK"),
YX(5,"YX"),
DY(6,"DY"),
;
private int id;