generated from root/miduo_server
增加充值代码
parent
62f99f5ba3
commit
a2c4571d89
|
|
@ -49,7 +49,7 @@ public class GameTitleController extends HttpServlet {
|
|||
String sign = parameterMap.get("sign");
|
||||
boolean isSignSuccess = false;
|
||||
for (String value : BaseGlobal.PAY_KEY.values()) {
|
||||
String info = accountid + roleId + HttpUtil.getEncode(roleName) +gameId + serviceId + opStatus + shutupTime + HttpUtil.getEncode(chatContents) + random + value;
|
||||
String info = accountid + roleId + HttpUtil.getEncode(roleName).toLowerCase() +gameId + serviceId + opStatus + shutupTime + HttpUtil.getEncode(chatContents) + random + value;
|
||||
String sig = MyMD5Util.encrypByMd5(info);
|
||||
if (sig.equals(sign)){
|
||||
isSignSuccess = true;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,9 @@
|
|||
package com.ljsd.controller;
|
||||
|
||||
import com.google.gson.Gson;
|
||||
import com.ljsd.pojo.ResultVo;
|
||||
import com.ljsd.redis.RedisKey;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
import com.ljsd.util.HttpUtil;
|
||||
import com.ljsd.util.MyMD5Util;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
|
@ -15,7 +13,11 @@ import javax.servlet.http.HttpServletRequest;
|
|||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.security.MessageDigest;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
|
||||
/**
|
||||
* @author gaojie
|
||||
|
|
@ -35,44 +37,39 @@ public class RebateController extends HttpServlet {
|
|||
resp.setContentType("application/json; charset=utf-8");
|
||||
PrintWriter out = resp.getWriter();
|
||||
HashMap<String, String> parameterMap = HttpUtil.getParameterMap(req);
|
||||
String rebateType = parameterMap.get("rebate_type");
|
||||
String rebate_no = parameterMap.get("rebate_no");
|
||||
String gameOrderNo = parameterMap.get("game_order_no");
|
||||
String accountid = parameterMap.get("user_id");
|
||||
String payMoney = parameterMap.get("pay_money");
|
||||
String gold = parameterMap.get("gold");
|
||||
String gameId = parameterMap.get("game_id");
|
||||
String serviceId = parameterMap.get("service_id");
|
||||
String sid = parameterMap.get("sid");
|
||||
String puid = parameterMap.get("puid");
|
||||
String roleid = parameterMap.get("roleid");
|
||||
String sendid = parameterMap.get("sendid");
|
||||
String amount = parameterMap.get("amount");
|
||||
String nonce = parameterMap.get("nonce");
|
||||
String props = parameterMap.get("props");
|
||||
String roleId = parameterMap.get("role_id");
|
||||
String roleName = parameterMap.get("role_name");
|
||||
String payTime = parameterMap.get("time");
|
||||
String payStatus = parameterMap.get("pay_status");
|
||||
String sign = parameterMap.get("sign");
|
||||
|
||||
boolean isSignSuccess = false;
|
||||
for (String value : BaseGlobal.PAY_KEY.values()) {
|
||||
String info =rebateType + rebate_no + HttpUtil.getUrlEncoder(gameOrderNo) + HttpUtil.getUrlEncoder(accountid) + payMoney + gold + gameId + HttpUtil.getUrlEncoder(serviceId)
|
||||
+ HttpUtil.getUrlEncoder(roleId) +payTime + value;
|
||||
String sig = MyMD5Util.encrypByMd5(info);
|
||||
String sig = generateSignature(parameterMap, value);
|
||||
if (sig.equals(sign)){
|
||||
isSignSuccess = true;
|
||||
break;
|
||||
}
|
||||
LOGGER.info("rebate()info={}, md5Sign={},sig" + "={} sin derify fail !!!",info,sign,sig);
|
||||
LOGGER.info("rebate()yg_md5Sign={},sig" + "={} sin derify fail !!!",sign,sig);
|
||||
}
|
||||
if (!isSignSuccess) {
|
||||
ResultVo resultVo = new ResultVo(100,"sign fail");
|
||||
out.print(HttpUtil.getResult(resultVo));
|
||||
out.print(HttpUtil.getYgResult("1","sign fail"));
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Gson gson = new Gson();
|
||||
BaseGlobal.redisApp.hset( serviceId + ":" + RedisKey.BT_REBATE_KEY,"",rebate_no,gson.toJson(parameterMap),-1);
|
||||
BaseGlobal.redisApp.hset( sid + ":" + RedisKey.YG_REBATE_KEY,"",sendid,gson.toJson(parameterMap),-1,false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
String result = HttpUtil.getResult(new ResultVo(200, "success"));
|
||||
String result =HttpUtil.getYgResult("0","success");
|
||||
LOGGER.info("RebateController==>url:{},result={}",req.getRequestURI(),result);
|
||||
out.print(result);
|
||||
out.flush();
|
||||
|
|
@ -82,4 +79,47 @@ public class RebateController extends HttpServlet {
|
|||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
this.doGet(req, resp);
|
||||
}
|
||||
|
||||
|
||||
public String generateSignature(Map<String, String> params, String secretKey){
|
||||
// 1. 将参数按键名进行升序排列
|
||||
TreeMap<String, String> sortedParams = new TreeMap<>(params);
|
||||
|
||||
// 2. 拼接参数
|
||||
StringBuilder queryStringBuilder = new StringBuilder();
|
||||
for (Map.Entry<String, String> entry : sortedParams.entrySet()) {
|
||||
if ("sign".equals(entry.getKey())){
|
||||
continue;
|
||||
}
|
||||
if (queryStringBuilder.length() > 0) {
|
||||
queryStringBuilder.append('&');
|
||||
}
|
||||
try {
|
||||
queryStringBuilder.append(entry.getKey()).append('=').append(HttpUtil.getUrlEncoder(entry.getValue())); // 手动进行 URL 编码
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 拼接游戏密钥
|
||||
queryStringBuilder.append('&').append(secretKey);
|
||||
|
||||
// 4. MD5 加密
|
||||
String queryString = queryStringBuilder.toString();
|
||||
LOGGER.info("generateSignature==>queryString:{}",queryString);
|
||||
String signature;
|
||||
MessageDigest md;
|
||||
try {
|
||||
md = MessageDigest.getInstance("MD5");
|
||||
byte[] bytes = md.digest(queryString.getBytes("UTF-8"));
|
||||
StringBuilder resultStringBuilder = new StringBuilder();
|
||||
for (byte b : bytes) {
|
||||
resultStringBuilder.append(String.format("%02x", b));
|
||||
}
|
||||
signature = resultStringBuilder.toString();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return signature;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,16 +2,13 @@ package com.ljsd.controller;
|
|||
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ljsd.pojo.KSConstant;
|
||||
import com.ljsd.pojo.KSPay;
|
||||
import com.ljsd.pojo.ResultVo;
|
||||
import com.ljsd.pojo.Pay;
|
||||
import com.ljsd.util.BaseGlobal;
|
||||
import com.ljsd.util.HttpUtil;
|
||||
import com.ljsd.util.MyMD5Util;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
|
@ -25,7 +22,7 @@ import java.util.Map;
|
|||
* @version V1.0
|
||||
* @className RechargeController
|
||||
* @packageName com.ljsd.controller
|
||||
* @description bt 充值
|
||||
* @description 幽谷 充值
|
||||
* @date 2022-02-21 14:10
|
||||
* copyright(c) 2020-2030 蓝鲸时代技术有限公司
|
||||
**/
|
||||
|
|
@ -38,79 +35,65 @@ public class RechargeController extends HttpServlet {
|
|||
resp.setContentType("application/json; charset=utf-8");
|
||||
PrintWriter out = resp.getWriter();
|
||||
HashMap<String, String> parameterMap = HttpUtil.getParameterMap(req);
|
||||
String orderNo = parameterMap.get("order_sn");
|
||||
String goodName = parameterMap.get("good_name");
|
||||
String gameOrderSn = parameterMap.get("game_order_sn");
|
||||
String accountid = parameterMap.get("uuid");
|
||||
String amount = parameterMap.get("pay_money");
|
||||
String gameId = parameterMap.get("game_id");
|
||||
String serviceId = parameterMap.get("service_id");
|
||||
String serviceName = parameterMap.get("service_name");
|
||||
String roleId = parameterMap.get("role_id");
|
||||
String roleName = parameterMap.get("role_name");
|
||||
String payTime = parameterMap.get("time");
|
||||
String payStatus = parameterMap.get("pay_status");
|
||||
String goodsInfo = parameterMap.get("remark");
|
||||
String couponAmount = parameterMap.get("coupon_amount");
|
||||
String sign = parameterMap.get("sign");
|
||||
int isTest = Integer.parseInt(parameterMap.get("is_test"));
|
||||
|
||||
String version = "zhj_bt";
|
||||
String serverId = parameterMap.get("sid");
|
||||
String uid = parameterMap.get("uid");
|
||||
String orderno = parameterMap.get("orderno");
|
||||
String amount = parameterMap.get("amount");
|
||||
// 暂时无用
|
||||
String isFreePay = parameterMap.get("isFreePay");
|
||||
String status = parameterMap.get("status");
|
||||
String extInfo = parameterMap.get("extinfo");
|
||||
String nonce = parameterMap.get("nonce");
|
||||
String token = parameterMap.get("token");
|
||||
boolean isSignSuccess = false;
|
||||
for (Map.Entry<String, String> entry : BaseGlobal.PAY_KEY.entrySet()) {
|
||||
String info = "good_name=" + HttpUtil.getUrlEncoder(goodName) + "&uuid="+accountid + "&order_sn="+orderNo + "&game_order_sn="+gameOrderSn + "&game_id="+gameId + "&service_id="
|
||||
+serviceId + "&service_name="+HttpUtil.getUrlEncoder(serviceName) + "&role_id=" + roleId + "&role_name=" + HttpUtil.getUrlEncoder(roleName) + "&pay_money=" + amount + "&pay_status=" + payStatus
|
||||
+"&remark=" + HttpUtil.getUrlEncoder(goodsInfo) + "&time=" + payTime + "&key=" + entry.getValue();
|
||||
String sig = MyMD5Util.encrypByMd5(info);
|
||||
if (sig.equals(sign)){
|
||||
for (String value : BaseGlobal.PAY_KEY.values()) {
|
||||
String info = serverId + uid + orderno + amount + extInfo + nonce + value;
|
||||
String sign = MyMD5Util.encrypByMd5(info);
|
||||
if (token.equals(sign)){
|
||||
isSignSuccess = true;
|
||||
version = entry.getKey();
|
||||
break;
|
||||
}
|
||||
LOGGER.info("callback()info={}, md5Sign={},sig={} sin derify fail !!!",info,sign,sig);
|
||||
LOGGER.info("callback()info={}, bt_md5Sign={},sig" + "={} sin derify fail !!!",info,sign,token);
|
||||
}
|
||||
if (!isSignSuccess) {
|
||||
ResultVo resultVo = new ResultVo(100,"sign fail");
|
||||
out.print(HttpUtil.getResult(resultVo));
|
||||
out.print(HttpUtil.getYgResult("1","sign fail"));
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
//init pay
|
||||
Gson gson = new Gson();
|
||||
String[] split = goodsInfo.split("\\|");
|
||||
String[] split = extInfo.split("\\|");
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("orderId", split[0]);
|
||||
jsonObject.addProperty("goodsId",split[1]);
|
||||
jsonObject.addProperty("welfareNum",split[2]);
|
||||
jsonObject.addProperty("uid",split[2]);
|
||||
// 游戏中uid
|
||||
Map<String, String> json = gson.fromJson(jsonObject, Map.class);
|
||||
KSPay pay = new KSPay();
|
||||
pay.app_id = version;
|
||||
pay.allin_trade_no = orderNo ;
|
||||
pay.goods_id = json.get("goodsId");
|
||||
pay.role_id = roleId;
|
||||
pay.server_id = serviceId;
|
||||
pay.data = payStatus;
|
||||
pay.extension = jsonObject.toString() ;
|
||||
Pay pay = new Pay();
|
||||
pay.roleId = json.get("uid");
|
||||
pay.serverId = serverId ;
|
||||
pay.goodsId = json.get("goodsId");
|
||||
pay.money = amount;
|
||||
pay.couponAmount = couponAmount;
|
||||
pay.extension = jsonObject.toString();
|
||||
pay.sdkOrderId = orderno;
|
||||
String orderId = json.get("orderId");
|
||||
//存入redis 存入成功就返回成功,后续在游戏服处理
|
||||
try {
|
||||
BaseGlobal.redisApp.hset("game", pay.server_id, "pay", KSConstant.KS_PAY, orderId, gson.toJson(pay), -1);
|
||||
BaseGlobal.redisApp.hset(pay.serverId, "PAY_KEY", orderId, gson.toJson(pay), -1,false);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
out.print("data error");
|
||||
out.flush();
|
||||
return;
|
||||
}
|
||||
LOGGER.info("玩家充值成功,存入redis----roleId={},orderId={},money={}", pay.role_id, pay.allin_trade_no,pay.money);
|
||||
String result = HttpUtil.getResult(new ResultVo(200, "success"));
|
||||
LOGGER.info("玩家充值成功,存入redis----roleId={},orderId={},money={}", pay.roleId, pay.sdkOrderId,pay.money);
|
||||
String result =HttpUtil.getYgResult("0","success");
|
||||
LOGGER.info("RechargeController==>url:{},result={}",req.getRequestURI(),result);
|
||||
out.print(result);
|
||||
out.flush();
|
||||
}
|
||||
@Override
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
|
||||
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||
this.doGet(req, resp);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
package com.ljsd.pojo;
|
||||
|
||||
/**
|
||||
* @version V1.0
|
||||
* @ClassName: KSPay
|
||||
* @Package com.ljsd.pojo
|
||||
* @Description: ${TODO}
|
||||
* @Author: zw
|
||||
* @date: 2020/7/28 18:30
|
||||
*/
|
||||
public class Pay {
|
||||
public String roleId;
|
||||
public String serverId;
|
||||
public String goodsId;
|
||||
public String money;
|
||||
public String extension;
|
||||
public String data;
|
||||
public String sdkOrderId;
|
||||
|
||||
}
|
||||
|
|
@ -21,6 +21,11 @@ public class ResultVo {
|
|||
this.data = "";
|
||||
}
|
||||
|
||||
public ResultVo(String code, String msg){
|
||||
this.msg = msg;
|
||||
this.data = "";
|
||||
}
|
||||
|
||||
public String getCode() {
|
||||
return status;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -156,8 +156,8 @@ public class RedisApp {
|
|||
public <K, T> void hset(final String type, final K key, final String field, final T value, int seconds,
|
||||
boolean withServerId) throws Exception {
|
||||
String fullKey = getKey(type, key, withServerId);
|
||||
String strValue = gson.toJson(value);
|
||||
redisUtil.hset(fullKey, field, strValue, seconds);
|
||||
// String strValue = gson.toJson(value);
|
||||
redisUtil.hset(fullKey, field, String.valueOf(value), seconds);
|
||||
}
|
||||
|
||||
//设置redis map一个键值 下的子key下的值 new---
|
||||
|
|
|
|||
|
|
@ -34,9 +34,9 @@ public interface RedisKey {
|
|||
*/
|
||||
String BT_SEND_REWARD_KEY = "BT_SEND_REWARD_KEY";
|
||||
/**
|
||||
* bt 充值返利
|
||||
* YG充值返利
|
||||
*/
|
||||
String BT_REBATE_KEY = "BT_REBATE_KEY";
|
||||
String YG_REBATE_KEY = "YG_REBATE_KEY";
|
||||
|
||||
/**
|
||||
* 禁言列表
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ public class BaseGlobal {
|
|||
for (Map.Entry<String, HashMap> mapEntry : sdkInfos.entrySet()) {
|
||||
String version = mapEntry.getKey();
|
||||
HashMap value = mapEntry.getValue();
|
||||
PAY_KEY.put(version, (String) value.get(GlobalSys.PAY_KEY));
|
||||
PAY_KEY.put(version, (String) value.get("pay_key"));
|
||||
LOGGER.info("init==>version={} PAY_KEY={},",version, PAY_KEY.get(version));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,19 +3,9 @@ package com.ljsd.util;
|
|||
public interface GlobalSys {
|
||||
int SERVER_GM_ID = 1000;
|
||||
|
||||
|
||||
String KEY = "f79012fe1147d62dcdaf67d6952ca42d";
|
||||
|
||||
String KEY_AQ = "88ead6d89711427f71febc0793bbec9f";
|
||||
|
||||
String KEY_QF = "e506dd6f38f6a50e5879bfab6165ede5";
|
||||
|
||||
String GAME_ID = "game_id";
|
||||
String LOGIN_KEY = "login_key";
|
||||
String PAY_KEY = "pay_key";
|
||||
|
||||
|
||||
String APP_ID = "230824152474";
|
||||
String YY_APP_KEY = "0dqescukctfzxvenirpjcb1f3txqcsaq";
|
||||
/**
|
||||
* 幽谷支付key
|
||||
*/
|
||||
String YG_PAY_KEY = "b09c8bb4c5764bc08fc20d75845e5839";
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ public class GlobalVersion {
|
|||
/**
|
||||
* 当前服务器编译版本号
|
||||
*/
|
||||
private static int serverBuildVersion = 111;
|
||||
private static int serverBuildVersion = 145;
|
||||
|
||||
public static String getServerVersion()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -5,9 +5,10 @@ import com.google.gson.GsonBuilder;
|
|||
import com.google.gson.JsonArray;
|
||||
import com.google.gson.JsonObject;
|
||||
import com.ljsd.pojo.ResultVo;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.IOException;
|
||||
|
|
@ -16,6 +17,7 @@ import java.io.UnsupportedEncodingException;
|
|||
import java.net.URLEncoder;
|
||||
import java.util.Enumeration;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class HttpUtil {
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(HttpUtil.class);
|
||||
|
|
@ -79,6 +81,13 @@ public class HttpUtil {
|
|||
public static String getResult(ResultVo resultVo) {
|
||||
return gson.toJson(resultVo);
|
||||
}
|
||||
public static String getYgResult(String errno, String errMsg) {
|
||||
Map<String,String> map = new HashMap<>();
|
||||
map.put("errno",errno);
|
||||
map.put("errmsg",errMsg);
|
||||
return gson.toJson(map);
|
||||
|
||||
}
|
||||
|
||||
public static String getReward(String itemInfo) {
|
||||
JsonArray items = gson.fromJson(itemInfo, JsonArray.class);
|
||||
|
|
|
|||
Loading…
Reference in New Issue