generated from root/miduo_server
117 lines
4.7 KiB
Java
117 lines
4.7 KiB
Java
package com.jmfy.controller;
|
|
|
|
import com.google.gson.Gson;
|
|
import com.jmfy.paramBean.PaySdkEnum;
|
|
import com.jmfy.util.HttpUtils;
|
|
import com.jmfy.util.JsonUtil;
|
|
import com.jmfy.util.MD5Util;
|
|
import net.sf.json.JSON;
|
|
import org.dom4j.Document;
|
|
import org.dom4j.DocumentException;
|
|
import org.dom4j.Element;
|
|
import org.dom4j.io.SAXReader;
|
|
import org.json.JSONObject;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
import org.springframework.web.bind.annotation.RestController;
|
|
import org.xml.sax.InputSource;
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import java.io.IOException;
|
|
import java.io.StringReader;
|
|
import java.util.*;
|
|
import java.util.regex.Matcher;
|
|
import java.util.regex.Pattern;
|
|
|
|
@RestController
|
|
public class VietnamGamotaRechargeController {
|
|
private static final Logger LOGGER = LoggerFactory.getLogger(VietnamGamotaRechargeController.class);
|
|
private static final String apikey = "GMA202401-4B0C8B6C-C3B7290DEC0B";
|
|
private static final String secretkey = "XAhRvf9ycmv6BJGTUJci";
|
|
|
|
@RequestMapping(value = "/GamotaCallback")
|
|
public String GamotaCallback(HttpServletRequest request) throws Exception {
|
|
return process(request,secretkey,apikey);
|
|
}
|
|
|
|
public static String process(HttpServletRequest request,String appsecret,String md5key) throws Exception{
|
|
JSONObject result = new JSONObject();
|
|
result.put("error_code",1);
|
|
result.put("messsage","Transaction fail");
|
|
|
|
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap2(request);
|
|
if (parameterMap.isEmpty()) {
|
|
LOGGER.error("request data is null");
|
|
result.put("messsage", "request data is null");
|
|
return result.toString();
|
|
}
|
|
|
|
Map<String, String> map = verifyOrder(parameterMap);
|
|
if (map == null || map.isEmpty()){
|
|
LOGGER.error("verify order is error");
|
|
result.put("messsage", "verify order is error");
|
|
return result.toString();
|
|
}
|
|
LOGGER.info("越南gamota支付验证结果:{}",map);
|
|
int errorCode = Integer.parseInt(map.get("error_code"));
|
|
if (errorCode != 0){
|
|
LOGGER.error("verify order is false");
|
|
result.put("messsage", "verify order is false");
|
|
return result.toString();
|
|
}
|
|
Gson gson = new Gson();
|
|
Map<String, String> data = gson.fromJson(map.get("data"), Map.class);
|
|
String inserted = insertOrder(parameterMap, data);
|
|
if ("SUCCESS".equals(inserted)) {
|
|
result.put("error_code",0);
|
|
result.put("message","success");
|
|
}
|
|
return result.toString();
|
|
}
|
|
|
|
public static Map<String, String> verifyOrder(Map<String,String> map) {
|
|
String url = "https://paygate.gamota.com/v1/services/check_transaction";
|
|
Map<String,String> parms = new HashMap<>();
|
|
parms.put("transaction_id",map.get("transaction_id"));
|
|
try {
|
|
Gson gson = new Gson();
|
|
String data = HttpUtils.doPost(url, parms);
|
|
LOGGER.info("越南gamota支付验证请求结果:{}",data);
|
|
return gson.fromJson(data, Map.class);
|
|
}catch (IOException e){
|
|
LOGGER.error("越南gamota支付验证请求报错",e);
|
|
return null;
|
|
}
|
|
}
|
|
|
|
/**
|
|
*
|
|
* @param params
|
|
* @param data
|
|
* 角色id_物品id_ccId_平台
|
|
* @return
|
|
*/
|
|
public static String insertOrder(Map<String,String> params, Map<String,String> data) {
|
|
String roleId = params.get("role_id");
|
|
String itemId = params.get("item_id");
|
|
String type = data.get("type");
|
|
String ccId = "0";
|
|
String callbackInfo = roleId + "_" + itemId + "_" +ccId + "_" + type;
|
|
String orderNo = data.get("transaction_id");
|
|
String amount = String.valueOf(Float.parseFloat(data.get("amount")) * 100);
|
|
Date time = new Date(System.currentTimeMillis());
|
|
String s = PayLogic.initOrder(callbackInfo, orderNo, amount, time, callbackInfo, PaySdkEnum.GAMOTA);
|
|
if ("ORDER_IS_EXIST".equals(s)) {
|
|
return "SUCCESS";
|
|
}
|
|
return s;
|
|
}
|
|
|
|
public static void main(String[] args) {
|
|
String a = "{\"error_code\":0,\"message\":\"Charging successfully!\",\"data\":{\"transaction_id\":\"AP20102226662769G\",\"type\":\"GOOGLE\",\"amount\":\"1.99\",\"vendor\":\"\",\"currency\":\"USD\",\"target\":\"username:XuanXuXu|userid:2618078\",\"state\":\"4_637389746321354058_9_1_1603352647\",\"sandbox\":1,\"time\":\"22\\/10\\/2020 14:44:20 GMT+7\",\"product_id\":\"com.gunx.item1.199\"}}";
|
|
Gson gson = new Gson();
|
|
System.out.println(gson.fromJson(a, Map.class));
|
|
}
|
|
}
|