generated from root/miduo_server
246 lines
9.4 KiB
Java
246 lines
9.4 KiB
Java
package com.jmfy.controller;
|
||
|
||
import com.jmfy.paramBean.PaySdkEnum;
|
||
import com.jmfy.util.HttpUtils;
|
||
import com.jmfy.util.JsonUtil;
|
||
import com.jmfy.util.MD5Util;
|
||
import org.slf4j.Logger;
|
||
import org.slf4j.LoggerFactory;
|
||
import org.springframework.web.bind.annotation.RequestMapping;
|
||
import org.springframework.web.bind.annotation.RestController;
|
||
|
||
import javax.servlet.http.HttpServletRequest;
|
||
import java.io.IOException;
|
||
import java.util.Date;
|
||
import java.util.HashMap;
|
||
import java.util.Map;
|
||
|
||
/**
|
||
* 太初行DNA01ios支付,该渠道安卓和ios要分开参数,比较诡异
|
||
*/
|
||
@RestController
|
||
public class Dna01IosRechargeController {
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(Dna01IosRechargeController.class);
|
||
private static final String iosAppId = "4";
|
||
private static final String iosAppKey = "94b817ed89ffe487fcdd280c35feb7fa";
|
||
|
||
@RequestMapping(value = "/Dna01IosCallback")
|
||
public String Dna01Callback(HttpServletRequest request) throws Exception {
|
||
return process(request,iosAppId,iosAppKey,"ios");
|
||
}
|
||
|
||
public static String process(HttpServletRequest request,String appId,String appKey,String type) throws Exception{
|
||
String result = "FAILURE";
|
||
HashMap<String, String> parameterMap = JsonUtil.getInstence().getParameterMap2(request);
|
||
if (parameterMap.isEmpty()) {
|
||
LOGGER.error("Dna01Callback request data is null");
|
||
return result;
|
||
}
|
||
if(!parameterMap.containsKey("app_id")){
|
||
LOGGER.error("Dna01Callback request app_id is null");
|
||
return result;
|
||
}
|
||
String appIdFrom = parameterMap.get("app_id");
|
||
if(appIdFrom == null){
|
||
LOGGER.error("Dna01Callback request app_id is null");
|
||
return result;
|
||
}
|
||
if(!appIdFrom.equals(appId)){
|
||
LOGGER.error("Dna01Callback request app_id is not exist channel app_id : " + appIdFrom + "---local app_id : " + appId);
|
||
return result;
|
||
}
|
||
if(!parameterMap.containsKey("ch_id")){
|
||
LOGGER.error("Dna01Callback request ch_id is null");
|
||
return result;
|
||
}
|
||
String chId = parameterMap.get("ch_id");
|
||
if(chId == null){
|
||
LOGGER.error("Dna01Callback request ch_id is null");
|
||
return result;
|
||
}
|
||
if(!parameterMap.containsKey("ch_order_id")){
|
||
LOGGER.error("Dna01Callback request ch_order_id is null");
|
||
return result;
|
||
}
|
||
String chOrderId = parameterMap.get("ch_order_id");
|
||
if(chOrderId == null){
|
||
LOGGER.error("Dna01Callback request ch_order_id is null");
|
||
return result;
|
||
}
|
||
if(!parameterMap.containsKey("order_id")){
|
||
LOGGER.error("Dna01Callback request order_id is null");
|
||
return result;
|
||
}
|
||
String orderId = parameterMap.get("order_id");
|
||
if(orderId == null){
|
||
LOGGER.error("Dna01Callback request orderId is null");
|
||
return result;
|
||
}
|
||
if(!parameterMap.containsKey("cp_order_id")){
|
||
LOGGER.error("Dna01Callback request cp_order_id is null");
|
||
return result;
|
||
}
|
||
String cpOrderId = parameterMap.get("cp_order_id");
|
||
if(cpOrderId == null){
|
||
LOGGER.error("Dna01Callback request cp_order_id is null");
|
||
return result;
|
||
}
|
||
if(!parameterMap.containsKey("mem_id")){
|
||
LOGGER.error("Dna01Callback request mem_id is null");
|
||
return result;
|
||
}
|
||
String userId = parameterMap.get("mem_id");
|
||
if(userId == null){
|
||
LOGGER.error("Dna01Callback request mem_id is null");
|
||
return result;
|
||
}
|
||
if(!parameterMap.containsKey("order_status")){
|
||
LOGGER.error("Dna01Callback request orderStatus is null");
|
||
return result;
|
||
}
|
||
String orderStatusStr = parameterMap.get("order_status");
|
||
if(orderStatusStr == null){
|
||
LOGGER.error("Dna01Callback request orderStatus is null");
|
||
return result;
|
||
}
|
||
int orderStatus = Integer.parseInt(orderStatusStr);
|
||
if(!parameterMap.containsKey("pay_time")){
|
||
LOGGER.error("Dna01Callback request pay_time is null");
|
||
return result;
|
||
}
|
||
String payTimeStr = parameterMap.get("pay_time");
|
||
if(payTimeStr == null){
|
||
LOGGER.error("Dna01Callback request pay_time is null");
|
||
return result;
|
||
}
|
||
int payTime = Integer.parseInt(payTimeStr);
|
||
if(!parameterMap.containsKey("finish_time")){
|
||
LOGGER.error("Dna01Callback request finish_time is null");
|
||
return result;
|
||
}
|
||
String finishTimeStr = parameterMap.get("finish_time");
|
||
if(finishTimeStr == null){
|
||
LOGGER.error("Dna01Callback request finish_time is null");
|
||
return result;
|
||
}
|
||
int finishTime = Integer.parseInt(finishTimeStr);
|
||
if(!parameterMap.containsKey("product_id")){
|
||
LOGGER.error("Dna01Callback request product_id is null");
|
||
return result;
|
||
}
|
||
String productId = parameterMap.get("product_id");
|
||
if(productId == null){
|
||
LOGGER.error("Dna01Callback request orderId is null");
|
||
return result;
|
||
}
|
||
if(!parameterMap.containsKey("product_name")){
|
||
LOGGER.error("Dna01Callback request product_name is null");
|
||
return result;
|
||
}
|
||
String productName = parameterMap.get("product_name");
|
||
if(productName == null){
|
||
LOGGER.error("Dna01Callback request productName is null");
|
||
return result;
|
||
}
|
||
if(!parameterMap.containsKey("product_price")){
|
||
LOGGER.error("Dna01Callback request product_price is null");
|
||
return result;
|
||
}
|
||
String moneyStr = parameterMap.get("product_price");
|
||
if(moneyStr == null){
|
||
LOGGER.error("Dna01Callback request product_price is null");
|
||
return result;
|
||
}
|
||
float money = Float.parseFloat(moneyStr);
|
||
if(!parameterMap.containsKey("server_id")){
|
||
LOGGER.error("Dna01Callback request server_id is null");
|
||
return result;
|
||
}
|
||
//ext参数传用户的uid即可
|
||
String serverId = parameterMap.get("server_id");
|
||
if(serverId == null){
|
||
LOGGER.error("Dna01Callback request server_id is null");
|
||
return result;
|
||
}
|
||
if(!parameterMap.containsKey("role_id")){
|
||
LOGGER.error("Dna01Callback request role_id is null");
|
||
return result;
|
||
}
|
||
//ext参数传用户的uid即可
|
||
String roleId = parameterMap.get("role_id");
|
||
if(roleId == null){
|
||
LOGGER.error("Dna01Callback request role_id is null");
|
||
return result;
|
||
}
|
||
if(!parameterMap.containsKey("ext")){
|
||
LOGGER.error("Dna01Callback request ext is null");
|
||
return result;
|
||
}
|
||
//ext参数传用户的uid即可
|
||
String extInfo = parameterMap.get("ext");
|
||
if(extInfo == null){
|
||
LOGGER.error("Dna01Callback request ext is null");
|
||
return result;
|
||
}
|
||
if(!parameterMap.containsKey("sign")){
|
||
LOGGER.error("Dna01Callback request sign is null");
|
||
return result;
|
||
}
|
||
String sign = parameterMap.get("sign");
|
||
if(sign == null){
|
||
LOGGER.error("Dna01Callback request sign is null");
|
||
return result;
|
||
}
|
||
StringBuffer signStr = new StringBuffer("app_id=" + appId);
|
||
signStr.append("&ch_id=" + chId);
|
||
signStr.append("&ch_order_id=" + chOrderId);
|
||
signStr.append("&cp_order_id=" + cpOrderId);
|
||
signStr.append("&ext=" + extInfo);
|
||
signStr.append("&finish_time=" + finishTime);
|
||
signStr.append("&mem_id=" + userId);
|
||
signStr.append("&order_id=" + orderId);
|
||
signStr.append("&order_status=" + orderStatus);
|
||
signStr.append("&pay_time=" + payTime);
|
||
signStr.append("&product_id=" + productId);
|
||
signStr.append("&product_name=" + productName);
|
||
signStr.append("&product_price=" + moneyStr);
|
||
signStr.append("&role_id=" + roleId);
|
||
signStr.append("&server_id=" + serverId);
|
||
signStr.append("&app_key=" + appKey);
|
||
String md5Str = MD5Util.encrypByMd5(signStr.toString());
|
||
if(!md5Str.equals(sign)){
|
||
LOGGER.error("Dna01Callback sign error md5Sign:" + md5Str + " -- md5Str:" + signStr.toString() + " -- sign:" + sign);
|
||
return result;
|
||
}
|
||
//充值成功
|
||
if(orderStatus == 2){
|
||
String inserted = insertOrder(roleId, productId,type,cpOrderId,money);
|
||
if("SUCCESS".equals(inserted)){
|
||
result = "SUCCESS";
|
||
}
|
||
}
|
||
return result;
|
||
}
|
||
|
||
/**
|
||
*
|
||
* @param roleId
|
||
* @param itemId
|
||
* @param type
|
||
* @param orderNo
|
||
* @param money
|
||
* @return
|
||
*/
|
||
public static String insertOrder(String roleId, String itemId,String type,String orderNo,float money) {
|
||
String ccId = "0";
|
||
String callbackInfo = roleId + "_" + itemId + "_" +ccId + "_" + type;
|
||
String amount = String.valueOf( money* 100);
|
||
Date time = new Date(System.currentTimeMillis());
|
||
String s = PayLogic.initOrder(callbackInfo, orderNo, amount, time, callbackInfo, PaySdkEnum.DNA01);
|
||
if ("ORDER_IS_EXIST".equals(s)) {
|
||
return "SUCCESS";
|
||
}
|
||
return s;
|
||
}
|
||
}
|