generated from root/miduo_server
217 lines
8.8 KiB
Java
217 lines
8.8 KiB
Java
package com.jmfy.controller;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.jmfy.dto.CPayOrder;
|
|
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.KTSDKConstans;
|
|
import com.jmfy.util.MD5Util;
|
|
import com.jmfy.util.MHTSDKConstans;
|
|
import org.apache.commons.lang.StringUtils;
|
|
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.UnsupportedEncodingException;
|
|
import java.lang.reflect.Field;
|
|
import java.net.URLDecoder;
|
|
import java.net.URLEncoder;
|
|
import java.nio.charset.StandardCharsets;
|
|
import java.text.DateFormat;
|
|
import java.text.SimpleDateFormat;
|
|
import java.util.*;
|
|
|
|
/**
|
|
* consumerId 游戏用户唯一标识
|
|
* consumerName Cp自定义信息
|
|
* orderNo 平台订单编号
|
|
* orderDetail 订单详情
|
|
* mhtOrderAmt 充值金额(分)
|
|
* time 平台支付时间
|
|
* sign 签名
|
|
*/
|
|
@RestController
|
|
public class MHTRechargeController {
|
|
@Resource
|
|
private CUserDao cuserDao;
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(MHTRechargeController.class);
|
|
// private static Gson gson = new Gson();
|
|
|
|
@RequestMapping(value = "/MHTcallback")
|
|
public String MHTcallback( HttpServletRequest request) throws Exception {
|
|
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap2(request);
|
|
if(parameterMap.isEmpty()) {
|
|
LOGGER.info( "data is null");
|
|
return "FAIL";
|
|
}
|
|
// String source = parameterMap.keySet().iterator().next();
|
|
// source = source.replaceAll(" ", "+");
|
|
// LOGGER.info(source);
|
|
// MHTRechargeRequestBean rechargeRequestBean = gson.fromJson(source, MHTRechargeRequestBean.class);
|
|
//
|
|
// MHTRechargeRequestBean.DataBean data = rechargeRequestBean.getData();
|
|
// if(data == null){
|
|
// LOGGER.info( "data is null");
|
|
// return "FAIL";
|
|
// }
|
|
String response = "SUCCESS";
|
|
try {
|
|
// String consumerid = parameterMap.get("consumerid");
|
|
String ext =parameterMap.get("ext");
|
|
String gameCurrency ="0";
|
|
String mhtOrderAmt =parameterMap.get("mhtOrderAmt");
|
|
String orderDetail =parameterMap.get("orderDetail");
|
|
String orderNo =parameterMap.get("orderNo");
|
|
String time =parameterMap.get("time");
|
|
String sign = parameterMap.get("sign");
|
|
String temp = "ext" + "=" + ext;
|
|
String stringBuilder = "ext" + "=" + ext + "&" +
|
|
"mhtOrderAmt" + "=" + mhtOrderAmt + "&" +
|
|
"orderDetail" + "=" + orderDetail + "&" +
|
|
"orderNo" + "=" + orderNo + "&" +
|
|
"time" + "=" + time;
|
|
|
|
LOGGER.info("stringBuilder"+stringBuilder);
|
|
LOGGER.info("temp"+temp);
|
|
|
|
|
|
String goodID;
|
|
String subChannel;
|
|
String uid;
|
|
if(ext.isEmpty()){
|
|
LOGGER.info("callback==>roleUid={},sin derify fail,old sign={} ",orderNo,sign);
|
|
return "FAIL";
|
|
}
|
|
|
|
String[] split1 = ext.split("_");
|
|
if(split1.length!=3){
|
|
LOGGER.info("callback==>roleUid={},sin derify fail,old sign={} ,EXT={}",orderNo,sign,ext);
|
|
}
|
|
uid = split1[0];
|
|
goodID = split1[1];
|
|
subChannel = split1[2];
|
|
if(null==uid||uid.isEmpty()||null==goodID||goodID.isEmpty()){
|
|
LOGGER.info("callback==>roleUid={},sin derify fail,old sign={} ,EXT={}",orderNo,sign,ext);
|
|
}
|
|
|
|
|
|
String plain;
|
|
|
|
if(subChannel.equals("1000")){
|
|
plain = stringBuilder + MD5Util.encrypByMd5(MHTSDKConstans.secretKey);
|
|
}else {
|
|
plain = stringBuilder + MD5Util.encrypByMd5(MHTSDKConstans.secretKeyOnline);
|
|
}
|
|
|
|
String sig = MD5Util.encrypByMd5(plain);
|
|
if (!sig.equals(sign)){
|
|
LOGGER.info("callback==>roleUid={},sin derify fail,mine sign={} subChannel={} ",ext,sig,subChannel);
|
|
return "FAIL";
|
|
}
|
|
|
|
|
|
CUserInfo cUserInfo = cuserDao.findUserInfo(Integer.valueOf(uid));
|
|
if(cUserInfo == null){
|
|
LOGGER.info( "该用户无此角色"+uid);
|
|
return "FAIL";
|
|
}
|
|
|
|
CPayOrder cPayOrder = cuserDao.getCpayOrderByOrderId(orderNo);
|
|
|
|
if (cPayOrder != null) {
|
|
LOGGER.info("callback==>creditId={},uId={} orderId is exit!!!",cUserInfo.getId(),cUserInfo.getOpenId());
|
|
return "FAIL";
|
|
} else {
|
|
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.setUserId(uid);
|
|
cPayOrder.setAmount(mhtOrderAmt);
|
|
cPayOrder.setGoodsId(goodID);
|
|
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(),goodID,uid, orderNo,0,(int)(Double.valueOf(mhtOrderAmt)*100));
|
|
} 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);
|
|
response = "FAIL";
|
|
}
|
|
if (result != null && result.getResultCode() == 1) {
|
|
LOGGER.info(" callback==>RPC result : ResultCode : " + result.getResultCode() + "; ResultMsg : " + result.getResultMsg());
|
|
cuserDao.addCpayOrder(cPayOrder);
|
|
} else {
|
|
response = "FAIL";
|
|
}
|
|
}
|
|
}catch (Exception e){
|
|
e.printStackTrace();
|
|
LOGGER.info("callback==>err "+e.toString());
|
|
response = "FAIL";
|
|
}
|
|
|
|
return response;
|
|
}
|
|
|
|
|
|
private static String getMySign( MHTRechargeRequestBean rechargeRequestBean ) throws IllegalAccessException {
|
|
StringBuilder stringBuilder = new StringBuilder();
|
|
MHTRechargeRequestBean.DataBean data = rechargeRequestBean.getData();
|
|
Class<? extends MHTRechargeRequestBean.DataBean> aClass = rechargeRequestBean.getData().getClass();
|
|
Field[] fields = aClass.getDeclaredFields();
|
|
for(Field field : fields){
|
|
field.setAccessible(true);
|
|
if("sign".equals(field.getName())){
|
|
continue;
|
|
}
|
|
String value = field.get(data).toString();
|
|
if(StringUtils.isEmpty(value)){
|
|
continue;
|
|
}
|
|
String key =field.getName();
|
|
stringBuilder.append(key).append("=").append(value).append("&");
|
|
}
|
|
String plain = stringBuilder.substring(0, stringBuilder.length() - 1) + MD5Util.encrypByMd5(MHTSDKConstans.secretKey);
|
|
return MD5Util.encrypByMd5(plain);
|
|
|
|
}
|
|
|
|
public static void main(String[] args) throws IllegalAccessException, UnsupportedEncodingException {
|
|
|
|
String plain = "ext=10044682_1&mhtOrderAmt=600.0&orderDetail=充值60妖晶&orderNo=2007240920401286471325669392384&time=1595553653080" + MD5Util.encrypByMd5(MHTSDKConstans.secretKey);
|
|
System.out.println("plain = " + plain);
|
|
String sig = MD5Util.encrypByMd5(plain);
|
|
System.out.println("sig = " + sig);
|
|
|
|
}
|
|
}
|