generated from root/miduo_server
add parm check
parent
40f3b6067d
commit
d2a22d0a3a
|
|
@ -1,5 +1,9 @@
|
||||||
package com.jmfy.controller;
|
package com.jmfy.controller;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonElement;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.reflect.TypeToken;
|
||||||
import com.jmfy.dto.*;
|
import com.jmfy.dto.*;
|
||||||
import com.jmfy.thrift.idl.RPCRequestIFace;
|
import com.jmfy.thrift.idl.RPCRequestIFace;
|
||||||
import com.jmfy.thrift.idl.Result;
|
import com.jmfy.thrift.idl.Result;
|
||||||
|
|
@ -8,41 +12,47 @@ import com.jmfy.thrift.pool.ServiceKey;
|
||||||
import com.jmfy.util.JsonUtil;
|
import com.jmfy.util.JsonUtil;
|
||||||
import com.jmfy.util.KTSDKConstans;
|
import com.jmfy.util.KTSDKConstans;
|
||||||
import com.jmfy.util.MD5Util;
|
import com.jmfy.util.MD5Util;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
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.annotation.Resource;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import java.lang.reflect.Field;
|
||||||
import java.text.DateFormat;
|
import java.text.DateFormat;
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.Date;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
@RestController
|
@RestController
|
||||||
public class RechargeController {
|
public class RechargeController {
|
||||||
@Resource
|
@Resource
|
||||||
private CUserDao cuserDao;
|
private CUserDao cuserDao;
|
||||||
private static final Logger LOGGER = LoggerFactory.getLogger(RechargeController.class);
|
private static final Logger LOGGER = LoggerFactory.getLogger(RechargeController.class);
|
||||||
|
|
||||||
@RequestMapping(value = "/callback")
|
@RequestMapping(value = "/callback")
|
||||||
public String callback(HttpServletRequest request) throws Exception {
|
public String callback(@RequestBody RechargeRequestBean rechargeRequestBean) throws Exception {
|
||||||
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap(request);
|
RechargeRequestBean.DataBean data = rechargeRequestBean.getData();
|
||||||
String orderId = parameterMap.get("orderId");
|
if(data == null){
|
||||||
String userId = parameterMap.get("userId");
|
ResultVo resultVo = new ResultVo(8, "data is null");
|
||||||
String productID = parameterMap.get("productID");
|
return JsonUtil.getInstence().getGson().toJson(resultVo);
|
||||||
int amount = Integer.parseInt(parameterMap.get("amount"));
|
}
|
||||||
String orderTime = parameterMap.get("orderTime");
|
String orderId =data.getOrder_id();
|
||||||
String sign = parameterMap.get("sign");
|
String userId = data.getUid();
|
||||||
String roleUid = parameterMap.get("roleUid");
|
String productID = data.getProductID();
|
||||||
String sig = MD5Util.encrypByMd5(orderId+userId+productID+amount+orderTime+roleUid+ KTSDKConstans.appkey);
|
int orderTime =data.getOrderTime();
|
||||||
|
String serverID = data.getServerID();
|
||||||
|
String sign = data.getSign();
|
||||||
|
String sig = getMySign(rechargeRequestBean);
|
||||||
|
|
||||||
if (!sig.equals(sign)){
|
if (!sig.equals(sign)){
|
||||||
LOGGER.info("callback==>roleUid={},sin derify fail ",roleUid);
|
LOGGER.info("callback==>roleUid={},sin derify fail ",userId);
|
||||||
ResultVo resultVo = new ResultVo(9, "sign fail");
|
ResultVo resultVo = new ResultVo(9, "sign fail");
|
||||||
return JsonUtil.getInstence().getGson().toJson(resultVo);
|
return JsonUtil.getInstence().getGson().toJson(resultVo);
|
||||||
}
|
}
|
||||||
|
|
||||||
CUserInfo cUserInfo = cuserDao.findUserInfo(Integer.parseInt(roleUid));
|
CUserInfo cUserInfo = cuserDao.findUserByOpenIdAndUidInfo(userId,serverID);
|
||||||
if(cUserInfo == null || !userId.equals(cUserInfo.getOpenId()) ){
|
if(cUserInfo == null || !userId.equals(cUserInfo.getOpenId()) ){
|
||||||
ResultVo resultVo = new ResultVo(10, "该用户无此角色");
|
ResultVo resultVo = new ResultVo(10, "该用户无此角色");
|
||||||
return JsonUtil.getInstence().getGson().toJson(resultVo);
|
return JsonUtil.getInstence().getGson().toJson(resultVo);
|
||||||
|
|
@ -61,7 +71,6 @@ public class RechargeController {
|
||||||
cPayOrder.setServerId(cUserInfo.getServerid());
|
cPayOrder.setServerId(cUserInfo.getServerid());
|
||||||
cPayOrder.setDelivery_time(date);
|
cPayOrder.setDelivery_time(date);
|
||||||
cPayOrder.setUserId(userId);
|
cPayOrder.setUserId(userId);
|
||||||
cPayOrder.setAmount(amount);
|
|
||||||
Result result = null;
|
Result result = null;
|
||||||
String userAddress = cuserDao.findUserAddress(cUserInfo.getId());
|
String userAddress = cuserDao.findUserAddress(cUserInfo.getId());
|
||||||
if (userAddress != null) {
|
if (userAddress != null) {
|
||||||
|
|
@ -75,7 +84,7 @@ public class RechargeController {
|
||||||
LOGGER.info("serviceKey : " + serviceKey);
|
LOGGER.info("serviceKey : " + serviceKey);
|
||||||
try {
|
try {
|
||||||
rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
|
rPCClient = ClientAdapterPo.getClientAdapterPo(serviceKey);
|
||||||
result = rPCClient.getClient().deliveryRecharge(cUserInfo.getId(),Integer.parseInt(productID),userId, orderId,Long.parseLong(orderTime),amount);
|
result = rPCClient.getClient().deliveryRecharge(cUserInfo.getId(),Integer.parseInt(productID),userId, orderId,orderTime,0);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LOGGER.info("callback=>",e);
|
LOGGER.info("callback=>",e);
|
||||||
}finally {
|
}finally {
|
||||||
|
|
@ -99,27 +108,45 @@ public class RechargeController {
|
||||||
return JsonUtil.getInstence().getGson().toJson(resultVo);
|
return JsonUtil.getInstence().getGson().toJson(resultVo);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
String orderId = "-1610530820";
|
|
||||||
String userId ="123151331.sujie";
|
|
||||||
String productID = "2";
|
|
||||||
int amount = 30;
|
|
||||||
|
|
||||||
String orderTime = "1562142276";
|
private static String getMySign( RechargeRequestBean rechargeRequestBean ) throws IllegalAccessException {
|
||||||
String roleUid ="20000056";
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
String sig = MD5Util.encrypByMd5(orderId+userId+productID+userId+amount+orderTime+roleUid+ KTSDKConstans.appkey);
|
TreeMap<String, String> tempMap = new TreeMap<>(new Comparator<String>() {
|
||||||
System.out.println(sig);
|
@Override
|
||||||
System.out.println(sig);
|
public int compare(String o1, String o2) {
|
||||||
StringBuilder stringBuilder = new StringBuilder();
|
return o1.compareTo(o2);
|
||||||
stringBuilder.append("orderId=").append(orderId).append("&");
|
}
|
||||||
stringBuilder.append("userId=").append(userId).append("&");
|
});
|
||||||
stringBuilder.append("productID=").append(productID).append("&");
|
RechargeRequestBean.DataBean data = rechargeRequestBean.getData();
|
||||||
stringBuilder.append("amount=").append(amount).append("&");
|
Class<? extends RechargeRequestBean.DataBean> aClass = rechargeRequestBean.getData().getClass();
|
||||||
stringBuilder.append("orderTime=").append(orderTime).append("&");
|
Field[] fields = aClass.getDeclaredFields();
|
||||||
stringBuilder.append("roleUid=").append(roleUid).append("&");
|
for(Field field : fields){
|
||||||
stringBuilder.append("sign=").append(sig);
|
field.setAccessible(true);
|
||||||
|
if("sign".equals(field.getName())){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
tempMap.put(field.getName(), field.get(data).toString());
|
||||||
|
}
|
||||||
|
for(Map.Entry<String,String> item : tempMap.entrySet()){
|
||||||
|
String value = item.getValue();
|
||||||
|
if(StringUtils.isEmpty(value)){
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
String key = item.getKey();
|
||||||
|
stringBuilder.append(key).append("=").append(value).append("#");
|
||||||
|
}
|
||||||
|
String plain = stringBuilder.substring(0, stringBuilder.length() - 1) + KTSDKConstans.appsecret;
|
||||||
|
System.out.println(plain);
|
||||||
|
return MD5Util.encrypByMd5(plain);
|
||||||
|
|
||||||
System.out.println(stringBuilder);
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) throws IllegalAccessException {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
String s = "{\"state\":1,\"data\":{\"order_id\":\"20190903150413100505555232904\",\"uid\":\"df63a9b82ebc6d886590fb23caa01f1b\",\"pchannel\":\"sy37\",\"appid\":\"129213\",\"serverID\":\"10153\",\"currency\":\"RMB\",\"ext\":\"MTQwMzgzODM2OC5zeTM3XzFfMV8yMDAwMDU5OV8xMDA4MV%2FmmIbku5HkuYvlt4U%3D\",\"productID\":\"1\",\"orderTime\":1567582220,\"pchannelOrderID\":\"B8894B116191F181226A47A27F643D2B\",\"sign\":\"724b49ed94634297a1d9c4f0c0112d8d\"}}";
|
||||||
|
RechargeRequestBean rechargeRequestBean = gson.fromJson(s, RechargeRequestBean.class);
|
||||||
|
String mySign = getMySign(rechargeRequestBean);
|
||||||
|
System.out.println(mySign);
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,145 @@
|
||||||
|
package com.jmfy.controller;
|
||||||
|
|
||||||
|
public class RechargeRequestBean {
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* state : 1
|
||||||
|
* data : {"order_id":"20190903150413100505555232904","uid":"1403838368.sy37","pchannel":"sy37","appid":"129213","serverID":"10081","currency":"RMB","ext":"MTQwMzgzODM2OC5zeTM3XzFfMV8yMDAwMDU5OV8xMDA4MV%2FmmIbku5HkuYvlt4U%3D","productID":"1","orderTime":1567575907,"pchannelOrderID":"B8894B116191F181226A47A27F643D2B","sign":"6f0dacbc9dc8c291d22b47df7018d5db"}
|
||||||
|
*/
|
||||||
|
|
||||||
|
private int state;
|
||||||
|
private DataBean data;
|
||||||
|
|
||||||
|
public int getState() {
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setState(int state) {
|
||||||
|
this.state = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DataBean getData() {
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setData(DataBean data) {
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class DataBean {
|
||||||
|
/**
|
||||||
|
* order_id : 20190903150413100505555232904
|
||||||
|
* uid : 1403838368.sy37
|
||||||
|
* pchannel : sy37
|
||||||
|
* appid : 129213
|
||||||
|
* serverID : 10081
|
||||||
|
* currency : RMB
|
||||||
|
* ext : MTQwMzgzODM2OC5zeTM3XzFfMV8yMDAwMDU5OV8xMDA4MV%2FmmIbku5HkuYvlt4U%3D
|
||||||
|
* productID : 1
|
||||||
|
* orderTime : 1567575907
|
||||||
|
* pchannelOrderID : B8894B116191F181226A47A27F643D2B
|
||||||
|
* sign : 6f0dacbc9dc8c291d22b47df7018d5db
|
||||||
|
*/
|
||||||
|
|
||||||
|
private String order_id;
|
||||||
|
private String uid;
|
||||||
|
private String pchannel;
|
||||||
|
private String appid;
|
||||||
|
private String serverID;
|
||||||
|
private String currency;
|
||||||
|
private String ext;
|
||||||
|
private String productID;
|
||||||
|
private int orderTime;
|
||||||
|
private String pchannelOrderID;
|
||||||
|
private String sign;
|
||||||
|
|
||||||
|
public String getOrder_id() {
|
||||||
|
return order_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrder_id(String order_id) {
|
||||||
|
this.order_id = order_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUid() {
|
||||||
|
return uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUid(String uid) {
|
||||||
|
this.uid = uid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPchannel() {
|
||||||
|
return pchannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPchannel(String pchannel) {
|
||||||
|
this.pchannel = pchannel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppid() {
|
||||||
|
return appid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppid(String appid) {
|
||||||
|
this.appid = appid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerID() {
|
||||||
|
return serverID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServerID(String serverID) {
|
||||||
|
this.serverID = serverID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCurrency() {
|
||||||
|
return currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrency(String currency) {
|
||||||
|
this.currency = currency;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getExt() {
|
||||||
|
return ext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExt(String ext) {
|
||||||
|
this.ext = ext;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProductID() {
|
||||||
|
return productID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProductID(String productID) {
|
||||||
|
this.productID = productID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getOrderTime() {
|
||||||
|
return orderTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOrderTime(int orderTime) {
|
||||||
|
this.orderTime = orderTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPchannelOrderID() {
|
||||||
|
return pchannelOrderID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPchannelOrderID(String pchannelOrderID) {
|
||||||
|
this.pchannelOrderID = pchannelOrderID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSign() {
|
||||||
|
return sign;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSign(String sign) {
|
||||||
|
this.sign = sign;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -3,6 +3,7 @@ package com.jmfy.dto;
|
||||||
public interface CUserDao {
|
public interface CUserDao {
|
||||||
|
|
||||||
CUserInfo findUserInfo(int uid) throws Exception;
|
CUserInfo findUserInfo(int uid) throws Exception;
|
||||||
|
CUserInfo findUserByOpenIdAndUidInfo(String openId,String serverId) throws Exception;
|
||||||
|
|
||||||
String findUserAddress(int uid);
|
String findUserAddress(int uid);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,9 @@ import com.jmfy.dto.CUserInfo;
|
||||||
import com.jmfy.redisProperties.RedisUserKey;
|
import com.jmfy.redisProperties.RedisUserKey;
|
||||||
import com.jmfy.util.Connect;
|
import com.jmfy.util.Connect;
|
||||||
import com.jmfy.util.RedisUtil;
|
import com.jmfy.util.RedisUtil;
|
||||||
|
import com.mongodb.BasicDBObject;
|
||||||
import org.springframework.data.mongodb.core.MongoTemplate;
|
import org.springframework.data.mongodb.core.MongoTemplate;
|
||||||
|
import org.springframework.data.mongodb.core.query.BasicQuery;
|
||||||
import org.springframework.data.mongodb.core.query.Criteria;
|
import org.springframework.data.mongodb.core.query.Criteria;
|
||||||
import org.springframework.data.mongodb.core.query.Query;
|
import org.springframework.data.mongodb.core.query.Query;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
|
|
@ -26,12 +28,17 @@ public class CUserDaoImpl implements CUserDao {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CUserInfo findUserInfo(int uid) throws Exception {
|
public CUserInfo findUserInfo(int uid) throws Exception {
|
||||||
Query query = new Query();
|
|
||||||
Criteria cr = new Criteria();
|
|
||||||
MongoTemplate mongoTemplate = connect.getMongoTemplete("jl_core");
|
MongoTemplate mongoTemplate = connect.getMongoTemplete("jl_core");
|
||||||
return mongoTemplate.findById(uid, CUserInfo.class);
|
return mongoTemplate.findById(uid, CUserInfo.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CUserInfo findUserByOpenIdAndUidInfo(String openId, String serverId) throws Exception {
|
||||||
|
MongoTemplate mongoTemplate = connect.getMongoTemplete("jl_core");
|
||||||
|
BasicQuery basicQuery = new BasicQuery(new BasicDBObject("openId", openId).append("serverId", serverId));
|
||||||
|
return mongoTemplate.findOne(basicQuery,CUserInfo.class);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String findUserAddress(int uid) {
|
public String findUserAddress(int uid) {
|
||||||
return RedisUtil.getInstence().getObject(RedisUserKey.USER_LOGIN_URL, Integer.toString(uid), String.class, -1);
|
return RedisUtil.getInstence().getObject(RedisUserKey.USER_LOGIN_URL, Integer.toString(uid), String.class, -1);
|
||||||
|
|
|
||||||
|
|
@ -79,7 +79,7 @@ public class MyStringRedisTemplate {
|
||||||
}
|
}
|
||||||
//设置密码
|
//设置密码
|
||||||
connectionFactory.setPassword(redisProperties.getPassword());
|
connectionFactory.setPassword(redisProperties.getPassword());
|
||||||
// connectionFactory.setDatabase(redisProperties.getDatabase());
|
connectionFactory.setDatabase(redisProperties.getDatabase());
|
||||||
|
|
||||||
//初始化connectionFactory
|
//初始化connectionFactory
|
||||||
connectionFactory.afterPropertiesSet();
|
connectionFactory.afterPropertiesSet();
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,11 @@
|
||||||
|
package com.jmfy.util;
|
||||||
|
|
||||||
|
public class StringUtils {
|
||||||
|
|
||||||
|
public static boolean checkIsEmpty(String source){
|
||||||
|
if(source == null || "".equals(source)){
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue