|
|
@@ -0,0 +1,130 @@
|
|
|
+package com.ljsd.controller;
|
|
|
+
|
|
|
+import com.google.gson.Gson;
|
|
|
+import com.ljsd.channel.MixSDK;
|
|
|
+import com.ljsd.channel.MsySDK;
|
|
|
+import com.ljsd.jieling.thrift.idl.Result;
|
|
|
+import com.ljsd.jieling.thrift.pool.ThriftClient;
|
|
|
+import com.ljsd.pojo.ResMsg;
|
|
|
+import com.ljsd.util.RequestLogger;
|
|
|
+import com.mongodb.BasicDBObject;
|
|
|
+import com.mongodb.DBObject;
|
|
|
+import org.apache.http.impl.client.CloseableHttpClient;
|
|
|
+import org.apache.http.impl.client.HttpClients;
|
|
|
+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;
|
|
|
+import java.io.IOException;
|
|
|
+import java.io.PrintWriter;
|
|
|
+
|
|
|
+public class PayCallback3Controller extends HttpServlet {
|
|
|
+ private static final Logger LOGGER = LoggerFactory.getLogger(PayCallback3Controller.class);
|
|
|
+ private static Gson gson = new Gson();
|
|
|
+ private final static String _COLLECTION_PAY = "pay";
|
|
|
+ private static final CloseableHttpClient httpClient = HttpClients.createDefault();
|
|
|
+
|
|
|
+ public PayCallback3Controller() {
|
|
|
+ super();
|
|
|
+ }
|
|
|
+
|
|
|
+ public void destroy() {
|
|
|
+ super.destroy();
|
|
|
+ }
|
|
|
+ public void doGet(HttpServletRequest request, HttpServletResponse response)
|
|
|
+ throws ServletException, IOException {
|
|
|
+ this.doPost(request, response);
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
|
|
|
+ request.setCharacterEncoding("UTF-8");
|
|
|
+ response.setCharacterEncoding("UTF-8");
|
|
|
+ response.setContentType("application/json; charset=utf-8");
|
|
|
+ LOGGER.info("PayCallbackController json params = {}", RequestLogger.logRequestParams(request));
|
|
|
+ String sign = request.getParameter("sign");
|
|
|
+ String appId = request.getParameter("appId");
|
|
|
+ String orderId = request.getParameter("orderId");
|
|
|
+ String cpOrderId = request.getParameter("cpOrderId");
|
|
|
+ String payMoney = request.getParameter("payMoney");
|
|
|
+ String payRealMoney = request.getParameter("payRealMoney");
|
|
|
+ //Double price = request.getParameter("price").isEmpty() ? null : Double.parseDouble(request.getParameter("price"));
|
|
|
+ int ts = Integer.parseInt(request.getParameter("ts"));
|
|
|
+ String extend = request.getParameter("extrasParams");
|
|
|
+ String uid = request.getParameter("uid");
|
|
|
+ LOGGER.info("Mix支付回调参数sign:{},orderId:{},cpOrderId:{},payMoney:{},payRealMoney:{},ts:{},extend:{},uid:{}",sign,orderId,cpOrderId,payMoney,payRealMoney,ts,extend,uid);
|
|
|
+ ResMsg resMsg = new ResMsg();
|
|
|
+ resMsg.setCode(1);
|
|
|
+ DBObject payInfo = new BasicDBObject();
|
|
|
+ try (PrintWriter out = response.getWriter();){
|
|
|
+ if (!appId.equals("33")){
|
|
|
+ resMsg.setMsg("appId验证失败");
|
|
|
+ LOGGER.error("appId验证失败");
|
|
|
+ out.print(gson.toJson(resMsg));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ boolean ok = false;
|
|
|
+ ok = MixSDK.verifyCallback(uid,orderId,cpOrderId,ts,appId,payMoney, payRealMoney,sign, extend);
|
|
|
+ if (ok) {
|
|
|
+ payInfo = MixSDK.saveDB(cpOrderId,payRealMoney,1, sign, extend,orderId,uid);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!ok) {
|
|
|
+ resMsg.setMsg("支付sign验证失败");
|
|
|
+ LOGGER.error("支付sign验证失败");
|
|
|
+ out.print(gson.toJson(resMsg));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (payInfo == null) {
|
|
|
+ resMsg.setMsg("订单验证失败");
|
|
|
+ LOGGER.error("订单验证失败");
|
|
|
+ out.print(gson.toJson(resMsg));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Object handleStatusObj = payInfo.get("handlestatus");
|
|
|
+ if (handleStatusObj != null) {
|
|
|
+ ///LOGGER.error("handlestatus is null for payInfo");
|
|
|
+ Integer handleStatus = null;
|
|
|
+ handleStatus = ((Number) handleStatusObj).intValue();
|
|
|
+ if (handleStatus==1){
|
|
|
+ LOGGER.error("11success");
|
|
|
+ out.print("success");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (handleStatus==2){
|
|
|
+ // out.print("success");
|
|
|
+ //resMsg.setCode(1);
|
|
|
+ resMsg.setMsg("订单错误");
|
|
|
+ out.print(gson.toJson(resMsg));
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 订单入库, 结构根据gameserver的PayVo推测的
|
|
|
+ // mongo db:x5_tk_login collect:pay
|
|
|
+ // status 怀疑没有使用,发货成功后,会把handlestatus置为1
|
|
|
+ // 放在各sdk实例的saveDB中
|
|
|
+
|
|
|
+ // 通知发货
|
|
|
+ LOGGER.info("通知发货, payInfo = {}", payInfo);
|
|
|
+ Result result = ThriftClient.deliveryRecharge((int) payInfo.get("uid"), (String) payInfo.get("pay_item"),
|
|
|
+ (String) payInfo.get("open_id"), (String) payInfo.get("billno"), Long.parseLong((String) payInfo.get("creattime")),
|
|
|
+ (int) payInfo.get("money"), (String) payInfo.get("region"));
|
|
|
+
|
|
|
+ LOGGER.info("deliveryRecharge result = {}", result);
|
|
|
+ if (result == null || result.resultCode != 1) {
|
|
|
+ resMsg.setCode(1);
|
|
|
+ resMsg.setMsg("发货失败");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ out.print("success");
|
|
|
+ }catch (Exception e){
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|