generated from root/miduo_server
草花支付
parent
44c5fa596a
commit
d4245a800f
|
@ -0,0 +1,210 @@
|
|||
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.paramBean.CHRechargeBean;
|
||||
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.StringUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
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.lang.reflect.Field;
|
||||
import java.text.DateFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2021/6/8
|
||||
* @discribe
|
||||
*/
|
||||
@RestController
|
||||
public class CHGnRechargeController {
|
||||
@Resource
|
||||
private CUserDao cuserDao;
|
||||
private static final Logger LOGGER = LoggerFactory.getLogger(CHGnRechargeController.class);
|
||||
private static Gson gson = new Gson();
|
||||
|
||||
|
||||
@RequestMapping(value = "/Web/CHGnCallback")
|
||||
public ResponseEntity CHGnCallback(HttpServletRequest request) throws Exception {
|
||||
ResponseEntity<String> tResponseEntity = new ResponseEntity<String>(HttpStatus.NON_AUTHORITATIVE_INFORMATION);
|
||||
return process(request,"2d74a35892ca1f4f8070bd6afe796cd9");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/Web/CHGnIosCallback")
|
||||
public ResponseEntity CHGnIosCallback(HttpServletRequest request) throws Exception {
|
||||
return process(request,"2d74a35892ca1f4f8070bd6afe796cd9");
|
||||
}
|
||||
|
||||
@RequestMapping(value = "/Web/CHGnTestCallback")
|
||||
public ResponseEntity CHGnTestCallback(HttpServletRequest request) throws Exception {
|
||||
return process(request,"2d74a35892ca1f4f8070bd6afe796cd9");
|
||||
}
|
||||
|
||||
protected ResponseEntity process(HttpServletRequest request,String appsecret) throws Exception{
|
||||
Map<String, String> parameterMap = JsonUtil.getInstence().getParameterMap2(request);
|
||||
ResponseEntity<String> responseEntity = new ResponseEntity<>(HttpStatus.NON_AUTHORITATIVE_INFORMATION);
|
||||
if (parameterMap.isEmpty()) {
|
||||
LOGGER.info("data is null");
|
||||
return responseEntity;
|
||||
}
|
||||
|
||||
CHRechargeBean data = getData(parameterMap);
|
||||
|
||||
if (data == null) {
|
||||
LOGGER.info("data is null");
|
||||
return responseEntity;
|
||||
}
|
||||
try {
|
||||
String consumerid = data.getUserid();
|
||||
String sign = data.getSign();
|
||||
|
||||
String sig = getMySign(data, appsecret);
|
||||
|
||||
if (!sig.equals(sign)) {
|
||||
responseEntity = new ResponseEntity<>(HttpStatus.OK);
|
||||
LOGGER.info("callback==>roleUid={},sin derify fail,mine sign={} ", consumerid, sig);
|
||||
return responseEntity;
|
||||
}
|
||||
|
||||
String response = insertOrder(data);
|
||||
if(response.equals("SUCCESS")){
|
||||
return new ResponseEntity<>(HttpStatus.OK);
|
||||
}else{
|
||||
return responseEntity;
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.info("callback==>err " + e.toString());
|
||||
return responseEntity;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private CHRechargeBean getData(Map<String, String> parameterMap) {
|
||||
CHRechargeBean rechargeRequestBean = gson.fromJson( new Gson().toJson(parameterMap), CHRechargeBean.class);
|
||||
return rechargeRequestBean;
|
||||
}
|
||||
|
||||
|
||||
private String insertOrder(CHRechargeBean data) {
|
||||
try {
|
||||
String user_id = data.getUserid();
|
||||
|
||||
String consumerName = data.getExtra();
|
||||
|
||||
String orderNo = data.getOrderno_cp();
|
||||
int amount = data.getPay_amt();
|
||||
String uid = user_id.split("_")[0];
|
||||
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(String.valueOf(amount));
|
||||
cPayOrder.setGoodsId(consumerName);
|
||||
// cPayOrder.setRecharge_type();
|
||||
|
||||
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(), consumerName, data.getExtra(), orderNo, 0, 0);
|
||||
} 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);
|
||||
return "FAIL";
|
||||
}
|
||||
if (result != null && result.getResultCode() == 1) {
|
||||
LOGGER.info(" callback==>RPC result : ResultCode : " + result.getResultCode() + "; ResultMsg : " + result.getResultMsg());
|
||||
cuserDao.addCpayOrder(cPayOrder);
|
||||
} else {
|
||||
System.out.println("测试代码");
|
||||
return "FAIL";
|
||||
}
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
LOGGER.info("callback==>err " + e.toString());
|
||||
return "FAIL";
|
||||
}
|
||||
return "SUCCESS";
|
||||
}
|
||||
|
||||
private static String getMySign(CHRechargeBean rechargeRequestBean,String appsecret) throws IllegalAccessException {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
TreeMap<String, String> tempMap = new TreeMap<>(new Comparator<String>() {
|
||||
@Override
|
||||
public int compare(String o1, String o2) {
|
||||
return o1.compareTo(o2);
|
||||
}
|
||||
});
|
||||
|
||||
Class<? extends CHRechargeBean> aClass = rechargeRequestBean.getClass();
|
||||
Field[] fields = aClass.getDeclaredFields();
|
||||
for (Field field : fields) {
|
||||
field.setAccessible(true);
|
||||
if ("sign".equals(field.getName())) {
|
||||
continue;
|
||||
}
|
||||
tempMap.put(field.getName(), field.get(rechargeRequestBean).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) + appsecret;
|
||||
System.out.println(plain);
|
||||
return MD5Util.encrypByMd5(plain);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,92 @@
|
|||
package com.jmfy.paramBean;
|
||||
|
||||
/**
|
||||
* @author lvxinran
|
||||
* @date 2021/6/8
|
||||
* @discribe
|
||||
*/
|
||||
public class CHRechargeBean {
|
||||
private String orderno;
|
||||
private String orderno_cp;
|
||||
private String userid;
|
||||
private int order_amt;
|
||||
private int pay_amt;
|
||||
private int pay_time;
|
||||
private String extra;
|
||||
private String sign;
|
||||
|
||||
public String getOrderno() {
|
||||
return orderno;
|
||||
}
|
||||
|
||||
public void setOrderno(String orderno) {
|
||||
this.orderno = orderno;
|
||||
}
|
||||
|
||||
public String getOrderno_cp() {
|
||||
return orderno_cp;
|
||||
}
|
||||
|
||||
public void setOrderno_cp(String orderno_cp) {
|
||||
this.orderno_cp = orderno_cp;
|
||||
}
|
||||
|
||||
public String getUserid() {
|
||||
return userid;
|
||||
}
|
||||
|
||||
public void setUserid(String userid) {
|
||||
this.userid = userid;
|
||||
}
|
||||
|
||||
public int getOrder_amt() {
|
||||
return order_amt;
|
||||
}
|
||||
|
||||
public void setOrder_amt(int order_amt) {
|
||||
this.order_amt = order_amt;
|
||||
}
|
||||
|
||||
public int getPay_amt() {
|
||||
return pay_amt;
|
||||
}
|
||||
|
||||
public void setPay_amt(int pay_amt) {
|
||||
this.pay_amt = pay_amt;
|
||||
}
|
||||
|
||||
public int getPay_time() {
|
||||
return pay_time;
|
||||
}
|
||||
|
||||
public void setPay_time(int pay_time) {
|
||||
this.pay_time = pay_time;
|
||||
}
|
||||
|
||||
public String getExtra() {
|
||||
return extra;
|
||||
}
|
||||
|
||||
public void setExtra(String extra) {
|
||||
this.extra = extra;
|
||||
}
|
||||
|
||||
public String getSign() {
|
||||
return sign;
|
||||
}
|
||||
|
||||
public void setSign(String sign) {
|
||||
this.sign = sign;
|
||||
}
|
||||
|
||||
public CHRechargeBean(String orderno, String orderno_cp, String userid, int order_amt, int pay_amt, int pay_time, String extra, String sign) {
|
||||
this.orderno = orderno;
|
||||
this.orderno_cp = orderno_cp;
|
||||
this.userid = userid;
|
||||
this.order_amt = order_amt;
|
||||
this.pay_amt = pay_amt;
|
||||
this.pay_time = pay_time;
|
||||
this.extra = extra;
|
||||
this.sign = sign;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue