Commit 69b9fd2d by yanlveming

同步

parent 3ae2713a
...@@ -6,15 +6,14 @@ import com.google.gson.JsonParser; ...@@ -6,15 +6,14 @@ import com.google.gson.JsonParser;
import com.library.TopUp.Http.HttpUtils; import com.library.TopUp.Http.HttpUtils;
import com.library.TopUp.Http.HttpsTool; import com.library.TopUp.Http.HttpsTool;
import com.library.TopUp.model.ResultsModel; import com.library.TopUp.model.ResultsModel;
import com.library.respcode.ServerResponse;
import com.wechat.pay.MD5Util; import com.wechat.pay.MD5Util;
import org.apache.http.util.TextUtils; import org.apache.http.util.TextUtils;
import java.math.BigDecimal;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.*;
import java.util.HashMap;
import java.util.Map;
import java.util.Random;
public class SeatelSentUtils { public class SeatelSentUtils {
...@@ -36,8 +35,7 @@ public class SeatelSentUtils { ...@@ -36,8 +35,7 @@ public class SeatelSentUtils {
try { try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); String time = getFormatedDateString(7);
String time = sdf.format(new Date());
String cmd = "queryphonenumberstatus"; String cmd = "queryphonenumberstatus";
String terminaltrace = "shoptest186" + new Random().nextInt(10000); String terminaltrace = "shoptest186" + new Random().nextInt(10000);
...@@ -75,15 +73,17 @@ public class SeatelSentUtils { ...@@ -75,15 +73,17 @@ public class SeatelSentUtils {
* *
* @return * @return
*/ */
public static String queryAgentFee() { public static String checkPhone2(String phone) {
try { try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = sdf.format(new Date());
String cmd = "queryagentfee"; String time = getFormatedDateString(7);
String terminaltrace = "shoptest183" + new Random().nextInt(10000);
String cmd = "queryphonenumberstatus";
String terminaltrace = UUID.randomUUID().toString().replace("-", "");
// String terminaltrace = generateKey()+new Random().nextInt(10000);;
Map params = new HashMap(); Map params = new HashMap();
params.put("cmd", cmd); params.put("cmd", cmd);
...@@ -91,20 +91,65 @@ public class SeatelSentUtils { ...@@ -91,20 +91,65 @@ public class SeatelSentUtils {
params.put("terminalid", terminalid); params.put("terminalid", terminalid);
params.put("terminaltrace", terminaltrace); params.put("terminaltrace", terminaltrace);
params.put("transtime", time); params.put("transtime", time);
params.put("phone", phone);
params.put("signtype", "MD5"); params.put("signtype", "MD5");
String sign = getSignStr(cmd, terminaltrace, time, ""); String sign = getSignStr(cmd, terminaltrace, time, phone);
params.put("sign", sign); params.put("sign", sign);
Map<String, String> heardMap = new HashMap<>(); Map<String, String> heardMap = new HashMap<>();
heardMap.put("Content-Type", "application/json"); heardMap.put("Content-Type", "application/json");
heardMap.put("Accept", "application/json"); heardMap.put("Accept", "application/json");
String strJson = "{" +
"\"cmd\":" + "\"" + cmd + "\"" + "," +
"\"shopid\":" + "\"" + shopid + "\"" + "," +
"\"terminalid\":" + "\"" + terminalid + "\"" + "," +
"\"terminaltrace\":" + "\"" + terminaltrace + "\"" + "," +
"\"transtime\":" + "\"" + time + "\"" + "," +
"\"phone\":" + "\"" + phone + "\"" + "," +
"\"signtype\":" + "\"" + "MD5" + "\"" + "," +
"\"sign\":" + "\"" + sign + "\"" + "," +
"}";
String json = HttpClientUtils.postWithJson(strJson, url, heardMap);
return json;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 查询账户余额,是否能充值
*
* @return
*/
public static String queryAgentFee() {
try {
String time = getFormatedDateString(7);
String cmd = "queryagentfee";
String terminaltrace = "shoptest183" + new Random().nextInt(10000);
// String json = HttpUtils.post(url, params, heardMap, 10000, 10000, "utf-8"); String sign = getSignStr(cmd, terminaltrace, time, "");
String json = HttpsTool.send(new Gson().toJson(params), heardMap, url, "utf-8", "utf-8", Map<String, String> heardMap = new HashMap<>();
10000, 10000, "application/json"); heardMap.put("Content-Type", "application/json");
heardMap.put("Accept", "application/json");
String strJson = "{" +
"\"cmd\":" + "\"" + cmd + "\"" + "," +
"\"shopid\":" + "\"" + shopid + "\"" + "," +
"\"terminalid\":" + "\"" + terminalid + "\"" + "," +
"\"terminaltrace\":" + "\"" + terminaltrace + "\"" + "," +
"\"transtime\":" + "\"" + time + "\"" + "," +
"\"signtype\":" + "\"" + "MD5" + "\"" + "," +
"\"sign\":" + "\"" + sign + "\"" + "," +
"}";
String json = HttpClientUtils.postWithJson(strJson, url, heardMap);
return json; return json;
} catch (Exception e) { } catch (Exception e) {
...@@ -113,6 +158,93 @@ public class SeatelSentUtils { ...@@ -113,6 +158,93 @@ public class SeatelSentUtils {
} }
} }
/**
* 发起充值
*
* @param phone 手机号码
* @param amount 充值金额,单位1美元 里面做了分转元的处理
* @return
*/
public static String crmRecharge(String phone, int amount) {
try {
String amountStr = String.valueOf(amount * 100);
String time = getFormatedDateString(7);
String cmd = "crmrecharge";
String terminaltrace = "shoptest183" + new Random().nextInt(10000);
String sign = getSignInTopUp(cmd, terminaltrace, time, phone, amountStr);
Map<String, String> heardMap = new HashMap<>();
heardMap.put("Content-Type", "application/json");
heardMap.put("Accept", "application/json");
String strJson = "{" +
"\"cmd\":" + "\"" + cmd + "\"" + "," +
"\"shopid\":" + "\"" + shopid + "\"" + "," +
"\"terminalid\":" + "\"" + terminalid + "\"" + "," +
"\"terminaltrace\":" + "\"" + terminaltrace + "\"" + "," +
"\"transtime\":" + "\"" + time + "\"" + "," +
"\"phone\":" + "\"" + phone + "\"" + "," +
"\"amount\":" + "" + amountStr + "" + "," +
"\"signtype\":" + "\"" + "MD5" + "\"" + "," +
"\"sign\":" + "\"" + sign + "\"" + "," +
"}";
String json = HttpClientUtils.postWithJson(strJson, url, heardMap);
return json;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
/**
* 查询充值结果
*
* @param systemtrace
* @return
*/
public static String queryCrmRecharge(String systemtrace) {
try {
String time = getFormatedDateString(7);
String cmd = "querycrmrecharge";
String terminaltrace = "shoptest183" + new Random().nextInt(10000);
// String sign = getSignStr(cmd, terminaltrace, time, "");
String str = cmd + shopid + terminalid + terminaltrace + time + systemtrace + "" + private_key;
String sign = MD5Util.MD5Encode(str, "");
Map<String, String> heardMap = new HashMap<>();
heardMap.put("Content-Type", "application/json");
heardMap.put("Accept", "application/json");
String strJson = "{" +
"\"cmd\":" + "\"" + cmd + "\"" + "," +
"\"shopid\":" + "\"" + shopid + "\"" + "," +
"\"terminalid\":" + "\"" + terminalid + "\"" + "," +
"\"terminaltrace\":" + "\"" + terminaltrace + "\"" + "," +
"\"transtime\":" + "\"" + time + "\"" + "," +
"\"systemtrace\":" + "\"" + systemtrace + "\"" + "," +
"\"signtype\":" + "\"" + "MD5" + "\"" + "," +
"\"sign\":" + "\"" + sign + "\"" + "," +
"}";
String json = HttpClientUtils.postWithJson(strJson, url, heardMap);
return json;
} catch (Exception e) {
e.printStackTrace();
return null;
}
}
private static String getSignStr(String cmd, String terminaltrace, String transtime, String phone) { private static String getSignStr(String cmd, String terminaltrace, String transtime, String phone) {
...@@ -121,6 +253,13 @@ public class SeatelSentUtils { ...@@ -121,6 +253,13 @@ public class SeatelSentUtils {
return md5Text; return md5Text;
} }
private static String getSignInTopUp(String cmd, String terminaltrace, String transtime, String phone, String amount) {
String str = cmd + "" + shopid + terminalid + terminaltrace + transtime + phone + amount + private_key;
String md5Text = MD5Util.MD5Encode(str, "");
return md5Text;
}
public static void main(String[] args) { public static void main(String[] args) {
String phone = "0189464112"; String phone = "0189464112";
...@@ -134,20 +273,103 @@ public class SeatelSentUtils { ...@@ -134,20 +273,103 @@ public class SeatelSentUtils {
} }
/** /**
* 发送Smart充值请求 * 发送充值请求
* *
* @param phone 手机号 * @param phone 手机号
* @param topUpAmount 单位1美元,里面已经做了1分钱转1元的处理了 * @param topUpAmount 单位1美元,里面已经做了1分钱转1元的处理了
* @param orderNum 需要确保唯一性,建议使用订单id *
*/ */
public static ResultsModel sentTopUp(String phone, int topUpAmount, String orderNum) { public static ResultsModel sentTopUp(String phone, int topUpAmount) {
String tip = ""; String tip = "";
boolean topUpSuccess = false; boolean topUpSuccess = false;
try { try {
ResultsModel resultsModel = new ResultsModel(topUpSuccess, tip); String feeJson = "";
String checkJson = checkPhone2(phone);
if (!TextUtils.isEmpty(checkJson)) {
JsonParser jsonParserCheck = new JsonParser();
JsonObject jsonObjectCheck = jsonParserCheck.parse(checkJson).getAsJsonObject();
String codeCheck = jsonObjectCheck.get("code") == null ? "" : jsonObjectCheck.get("code").getAsString();
if (!TextUtils.isEmpty(codeCheck) && codeCheck.equals("0")) {
//号码校验成功,发起查询余额
feeJson = queryAgentFee();
} else {
tip += "校验号码失败;结果为:" + checkJson;
}
}
String rechargeJson = "";
if (!TextUtils.isEmpty(feeJson)) {
JsonParser jsonParserFee = new JsonParser();
JsonObject jsonObjectFee = jsonParserFee.parse(feeJson).getAsJsonObject();
String codeCheck = jsonObjectFee.get("code") == null ? "" : jsonObjectFee.get("code").getAsString();
if (!TextUtils.isEmpty(codeCheck) && codeCheck.equals("0")) {
//接口查询成功,比较金额大小
if (jsonObjectFee.get("amount") != null) {
BigDecimal myAmount = jsonObjectFee.get("amount").getAsBigDecimal();
if (myAmount.compareTo(new BigDecimal(topUpAmount)) >= 0) {
//余额充足
rechargeJson = crmRecharge(phone, topUpAmount);
} else {
//余额不足
tip += "余额不足,请充值";
}
} else {
tip += "获取不到余额信息";
}
} else {
tip += "校验号码失败;结果为:" + feeJson;
}
}
String queryResultJson = "";
String systemtrace = "";
if (!TextUtils.isEmpty(rechargeJson)) {
//充值请求成功
JsonParser jsonParserRecharge = new JsonParser();
JsonObject jsonObjectRecharge = jsonParserRecharge.parse(rechargeJson).getAsJsonObject();
String codeCheck = jsonObjectRecharge.get("code") == null ? "" : jsonObjectRecharge.get("code").getAsString();
if (!TextUtils.isEmpty(codeCheck) && codeCheck.equals("0")) {
//充值成功
tip += "充值成功!!! 发起复查;";
// topUpSuccess = true;//复查成功,再更改
systemtrace = jsonObjectRecharge.get("systemtrace") == null ? "" : jsonObjectRecharge.get("systemtrace").getAsString();
queryResultJson = queryCrmRecharge(systemtrace);
} else {
tip += "充值失败,返回结果:" + rechargeJson;
}
}
if (!TextUtils.isEmpty(queryResultJson)) {
JsonParser jsonParserResult = new JsonParser();
JsonObject jsonObjectResult = jsonParserResult.parse(queryResultJson).getAsJsonObject();
String codeCheck = jsonObjectResult.get("code") == null ? "" : jsonObjectResult.get("code").getAsString();
if (!TextUtils.isEmpty(codeCheck) && codeCheck.equals("0")) {
String crmstatus = jsonObjectResult.get("crmstatus") == null ? "" : jsonObjectResult.get("crmstatus").getAsString();
if (crmstatus.equals("successed")) {
//检查结果,充值成功
topUpSuccess = true;
tip += "检查结果,充值成功。";
} else {
tip += "检查结果,充值失败。";
}
} else {
tip += "请求复查错误,解析如下:" + queryResultJson;
}
}
ResultsModel resultsModel = new ResultsModel(topUpSuccess, tip, systemtrace);
resultsModel.setTopUpNum(systemtrace);
return resultsModel; return resultsModel;
} catch (Exception e) { } catch (Exception e) {
...@@ -156,4 +378,38 @@ public class SeatelSentUtils { ...@@ -156,4 +378,38 @@ public class SeatelSentUtils {
return resultsModel; return resultsModel;
} }
} }
public static String generateKey() {
String key = UUID.randomUUID().toString();
key = key.replace("-", "").substring(0, 16);// 替换掉-号
return key;
}
/**
* 此函数非原创,从网上搜索而来,timeZoneOffset原为int类型,为班加罗尔调整成float类型
* timeZoneOffset表示时区,如中国一般使用东八区,因此timeZoneOffset就是8
*
* @param timeZoneOffset
* @return
*/
public static String getFormatedDateString(float timeZoneOffset) {
if (timeZoneOffset > 13 || timeZoneOffset < -12) {
timeZoneOffset = 0;
}
int newTime = (int) (timeZoneOffset * 60 * 60 * 1000);
TimeZone timeZone;
String[] ids = TimeZone.getAvailableIDs(newTime);
if (ids.length == 0) {
timeZone = TimeZone.getDefault();
} else {
timeZone = new SimpleTimeZone(newTime, ids[0]);
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(timeZone);
return sdf.format(new Date());
}
} }
...@@ -5,6 +5,7 @@ public class ResultsModel { ...@@ -5,6 +5,7 @@ public class ResultsModel {
private boolean isSuccessful; private boolean isSuccessful;
private String tip; private String tip;
private String expandText; private String expandText;
private String topUpNum;
public ResultsModel(boolean isSuccessful, String tip) { public ResultsModel(boolean isSuccessful, String tip) {
...@@ -44,4 +45,12 @@ public class ResultsModel { ...@@ -44,4 +45,12 @@ public class ResultsModel {
public void setExpandText(String expandText) { public void setExpandText(String expandText) {
this.expandText = expandText; this.expandText = expandText;
} }
public String getTopUpNum() {
return topUpNum;
}
public void setTopUpNum(String topUpNum) {
this.topUpNum = topUpNum;
}
} }
...@@ -174,43 +174,6 @@ public class SmartSentUtils { ...@@ -174,43 +174,6 @@ public class SmartSentUtils {
} }
} }
public static void main2222(String[] args) {
String json = getToken();
// //{"access_token":"372b5f81-9662-3d75-abcf-639920880ce3","refresh_token":"d62d9da3-3730-35f7-9368-c82b43509db1","scope":"default","token_type":"Bearer","expires_in":3249}//
System.out.println(json);
String tip = "";
if (!TextUtils.isEmpty(json)) {
JsonParser jsonParser = new JsonParser();
JsonObject jsonObject = jsonParser.parse(json).getAsJsonObject();
String token = jsonObject.get("access_token").getAsString();
if (!TextUtils.isEmpty(token)) {
access_token = token;
refresh_token = jsonObject.get("refresh_token").getAsString();
token_type = jsonObject.get("token_type").getAsString();
expires_in = jsonObject.get("expires_in").getAsInt();
} else {
tip += "返回结果:" + json;
}
} else {
tip += "返回值为空";
}
System.out.println(tip);
String jsonQuery = queryRechargePhone("58cam:87234159:100025");
System.out.println(jsonQuery);
if (!TextUtils.isEmpty(jsonQuery)) {
JsonParser jsonQueryParser = new JsonParser();
JsonObject jsonObjectQuery = jsonQueryParser.parse(jsonQuery).getAsJsonObject();
String recharge_status = jsonObjectQuery.get("recharge_status").getAsString();
if (recharge_status.equals("Succeeded")) {
System.out.println("充值成功");
}
}
}
public static void main(String[] args) { public static void main(String[] args) {
String phone = "87234159"; String phone = "87234159";
......
...@@ -5,6 +5,7 @@ import com.library.TopUp.Http.HttpUtils; ...@@ -5,6 +5,7 @@ import com.library.TopUp.Http.HttpUtils;
import com.library.TopUp.Statel.HttpClientUtils; import com.library.TopUp.Statel.HttpClientUtils;
import com.library.TopUp.Statel.SeatelSentUtils; import com.library.TopUp.Statel.SeatelSentUtils;
import com.library.TopUp.cellcard.CellcardSentUtils; import com.library.TopUp.cellcard.CellcardSentUtils;
import com.library.TopUp.model.ResultsModel;
import com.library.respcode.ServerResponse; import com.library.respcode.ServerResponse;
import com.library.service.AdminService; import com.library.service.AdminService;
import com.library.service.CommService; import com.library.service.CommService;
...@@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping; ...@@ -15,6 +16,7 @@ import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.bind.annotation.ResponseBody;
import javax.annotation.Resource; import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
...@@ -36,6 +38,8 @@ public class CommonController { ...@@ -36,6 +38,8 @@ public class CommonController {
@Resource @Resource
private CommService commService; private CommService commService;
@Resource
private HttpServletRequest request;
//获取七牛云的token //获取七牛云的token
@ResponseBody @ResponseBody
...@@ -61,11 +65,11 @@ public class CommonController { ...@@ -61,11 +65,11 @@ public class CommonController {
//登录 //登录
@ResponseBody @ResponseBody
@RequestMapping("test") @RequestMapping("test1")
private ServerResponse test() { private ServerResponse test() {
String json = CellcardSentUtils.getToken(); String phone = "0189464112";
System.out.println(json); String json = SeatelSentUtils.checkPhone(phone);
return ServerResponse.createBySuccess(json); return ServerResponse.createBySuccess(json);
} }
...@@ -75,7 +79,7 @@ public class CommonController { ...@@ -75,7 +79,7 @@ public class CommonController {
private ServerResponse test2() { private ServerResponse test2() {
String phone = "0189464112"; String phone = "0189464112";
String json = SeatelSentUtils.checkPhone(phone); String json = SeatelSentUtils.checkPhone2(phone);
return ServerResponse.createBySuccess(json); return ServerResponse.createBySuccess(json);
} }
...@@ -88,136 +92,32 @@ public class CommonController { ...@@ -88,136 +92,32 @@ public class CommonController {
return ServerResponse.createBySuccess(json); return ServerResponse.createBySuccess(json);
} }
final String url = "http://172.22.188.20:11999/SeatelPayment/pay.jsp";//测试
// public final static String url = "http://172.22.188.20:11800/SeatelPayment/pay.jsp";//生产
final String shopid = "shoptest";
final String private_key = "9834a62b4ec7c78a5424932bfdedfd74";
final String terminalid = "shoptest0001";
@ResponseBody @ResponseBody
@RequestMapping("test11") @RequestMapping("test4")
private ServerResponse test11() { private ServerResponse test4() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = sdf.format(new Date());
String cmd = "queryphonenumberstatus";
String terminaltrace = "shoptest186" + new Random().nextInt(10000);
String phone = "0189464112"; String phone = "0189464112";
String json = SeatelSentUtils.crmRecharge(phone, 1);
Map params = new HashMap();
params.put("cmd", cmd);
params.put("shopid", shopid);
params.put("terminalid", terminalid);
params.put("terminaltrace", terminaltrace);
params.put("transtime", time);
params.put("phone", phone);
params.put("signtype", "MD5");
String sign = getSignStr(cmd, terminaltrace, time, phone);
params.put("sign", sign);
Map<String, String> heardMap = new HashMap<>();
heardMap.put("Content-Type", "application/json");
heardMap.put("Accept", "application/json");
// HttpClientResult clientResult = HttpClientUtils.doGet(url, heardMap, params);
String json = HttpClientUtils.postWithJson(new Gson().toJson(params), url, heardMap);
return ServerResponse.createBySuccess(json); return ServerResponse.createBySuccess(json);
} }
@ResponseBody @ResponseBody
@RequestMapping("test12") @RequestMapping("test5")
private ServerResponse test12() { private ServerResponse test5() {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String time = sdf.format(new Date());
String cmd = "queryphonenumberstatus";
String terminaltrace = "shoptest186" + new Random().nextInt(10000);
String phone = "0189464112"; String str = request.getParameter("str");
String type = request.getParameter("type");
Map params = new HashMap(); String json = SeatelSentUtils.queryCrmRecharge(str);
params.put("cmd", cmd);
params.put("shopid", shopid);
params.put("terminalid", terminalid);
params.put("terminaltrace", terminaltrace);
params.put("transtime", time);
params.put("phone", phone);
params.put("signtype", "MD5");
String sign = getSignStr(cmd, terminaltrace, time, phone);
params.put("sign", sign);
Map<String, String> heardMap = new HashMap<>();
heardMap.put("Content-Type", "application/json");
heardMap.put("Accept", "application/json");
// HttpClientResult clientResult = HttpClientUtils.doGet(url, heardMap, params);
// String json = HttpClientUtils.postWithJson(new Gson().toJson(params), url, heardMap);
String json = HttpUtils.post(url, params, heardMap, 30000, 30000, "utf-8");
return ServerResponse.createBySuccess(json); return ServerResponse.createBySuccess(json);
} }
@ResponseBody @ResponseBody
@RequestMapping("test13") @RequestMapping("sentTopUp")
private ServerResponse test13() { private ServerResponse sentTopUp() {
String phone = request.getParameter("phone");
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); // String phone = "0189464112";
String time = sdf.format(new Date()); ResultsModel resultsModel = SeatelSentUtils.sentTopUp(phone,1);
return ServerResponse.createBySuccess(new Gson().toJson(resultsModel));
String cmd = "queryphonenumberstatus";
String terminaltrace = "shoptest186" + new Random().nextInt(10000);
String phone = "0189464112";
Map params = new HashMap();
params.put("cmd", cmd);
params.put("shopid", shopid);
params.put("terminalid", terminalid);
params.put("terminaltrace", terminaltrace);
params.put("transtime", time);
params.put("phone", phone);
params.put("signtype", "MD5");
String sign = getSignStr(cmd, terminaltrace, time, phone);
params.put("sign", sign);
Map<String, String> heardMap = new HashMap<>();
heardMap.put("Content-Type", "application/json");
heardMap.put("Accept", "application/json");
// HttpClientResult clientResult = HttpClientUtils.doGet(url, heardMap, params);
// String json = HttpClientUtils.postWithJson(new Gson().toJson(params), url, heardMap);
String strJson = "{" +
"\"cmd\":" + "\"" + cmd + "\"" + "," +
"\"shopid\":" + "\"" + shopid + "\"" + "," +
"\"terminalid\":" + "\"" + terminalid + "\"" + "," +
"\"terminaltrace\":" + "\"" + terminaltrace + "\"" + "," +
"\"transtime\":" + "\"" + time + "\"" + "," +
"\"phone\":" + "\"" + phone + "\"" + "," +
"\"signtype\":" + "\"" + "MD5" + "\"" + "," +
"\"sign\":" + "\"" + sign + "\"" + "," +
"}";
String json = HttpClientUtils.postWithJson(strJson, url, heardMap);
return ServerResponse.createBySuccess(json);
}
private String getSignStr(String cmd, String terminaltrace, String transtime, String phone) {
String str = cmd + "" + shopid + terminalid + terminaltrace + transtime + phone + private_key;
String md5Text = MD5Util.MD5Encode(str, "");
return md5Text;
} }
......
package com.library.service.Impl; package com.library.service.Impl;
import com.library.TopUp.Statel.SeatelSentUtils;
import com.library.TopUp.cellcard.CellcardSentUtils; import com.library.TopUp.cellcard.CellcardSentUtils;
import com.library.TopUp.mefont.MetfoneSentUtils; import com.library.TopUp.mefont.MetfoneSentUtils;
import com.library.TopUp.model.ResultsModel; import com.library.TopUp.model.ResultsModel;
...@@ -90,7 +91,6 @@ public class AutomaticCodeServiceImpl implements AutomaticCodeService { ...@@ -90,7 +91,6 @@ public class AutomaticCodeServiceImpl implements AutomaticCodeService {
currencyMapper.AddTableForMysql(TransformationTools.CreatAddMysql(orderLogModel, NameValue.Table_order_log, "id", null)); currencyMapper.AddTableForMysql(TransformationTools.CreatAddMysql(orderLogModel, NameValue.Table_order_log, "id", null));
//生成充值的订单编号。每次都会变,以后可能会复查使用到。 //生成充值的订单编号。每次都会变,以后可能会复查使用到。
SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
top_up_num = sdf.format(new Date()); top_up_num = sdf.format(new Date());
...@@ -99,6 +99,7 @@ public class AutomaticCodeServiceImpl implements AutomaticCodeService { ...@@ -99,6 +99,7 @@ public class AutomaticCodeServiceImpl implements AutomaticCodeService {
ResultsModel resultsModel = sentTopup(automaticQueueModel, top_up_num); ResultsModel resultsModel = sentTopup(automaticQueueModel, top_up_num);
desc = resultsModel.getTip(); desc = resultsModel.getTip();
success = resultsModel.isSuccessful(); success = resultsModel.isSuccessful();
top_up_num = resultsModel.getTopUpNum();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
...@@ -106,7 +107,7 @@ public class AutomaticCodeServiceImpl implements AutomaticCodeService { ...@@ -106,7 +107,7 @@ public class AutomaticCodeServiceImpl implements AutomaticCodeService {
} }
// 自动处理结果 // 自动处理结果
this.automaticForTackResult(automaticQueueModel, success, desc,top_up_num); this.automaticForTackResult(automaticQueueModel, success, desc, top_up_num);
} }
} }
...@@ -131,21 +132,16 @@ public class AutomaticCodeServiceImpl implements AutomaticCodeService { ...@@ -131,21 +132,16 @@ public class AutomaticCodeServiceImpl implements AutomaticCodeService {
if (segmentModel.getOperator().equals(SegmentType_Cellcard)) { if (segmentModel.getOperator().equals(SegmentType_Cellcard)) {
//Cellcard的手机号,则选择Cellcard公司的api发起充值 //Cellcard的手机号,则选择Cellcard公司的api发起充值
resultsModel = CellcardSentUtils.sentTopUp(automaticQueueModel.getOrder_phone(), orderNumId, automaticQueueModel.getOrder_money().intValue()); resultsModel = CellcardSentUtils.sentTopUp(automaticQueueModel.getOrder_phone(), orderNumId, automaticQueueModel.getOrder_money().intValue());
resultsModel.setTopUpNum(orderNumId);
} else if (segmentModel.getOperator().equals(SegmentType_Metfone)) { } else if (segmentModel.getOperator().equals(SegmentType_Metfone)) {
resultsModel = MetfoneSentUtils.sentTopUp(automaticQueueModel.getOrder_phone(), automaticQueueModel.getOrder_money().intValue(), orderNumId); resultsModel = MetfoneSentUtils.sentTopUp(automaticQueueModel.getOrder_phone(), automaticQueueModel.getOrder_money().intValue(), orderNumId);
resultsModel.setTopUpNum(orderNumId);
} else if (segmentModel.getOperator().equals(SegmentType_Smart)) { } else if (segmentModel.getOperator().equals(SegmentType_Smart)) {
resultsModel = SmartSentUtils.sentTopUp(automaticQueueModel.getOrder_phone(), automaticQueueModel.getOrder_money().intValue(), orderNumId); resultsModel = SmartSentUtils.sentTopUp(automaticQueueModel.getOrder_phone(), automaticQueueModel.getOrder_money().intValue(), orderNumId);
resultsModel.setTopUpNum(orderNumId);
} else if (segmentModel.getOperator().equals(SegmentType_Seatel)) { } else if (segmentModel.getOperator().equals(SegmentType_Seatel)) {
Paygo24Utils paygo = new Paygo24Utils(); resultsModel = SeatelSentUtils.sentTopUp(automaticQueueModel.getOrder_phone(), automaticQueueModel.getOrder_money().intValue());
String result = paygo.payment(automaticQueueModel.getOrder_phone(), automaticQueueModel.getSegment_id(), automaticQueueModel.getOrder_money()); //这个不用返回订单num,里面已经做了处理
resultsModel = new ResultsModel();
resultsModel.setTip(result);//描述
if (result.equals(Paygo24Utils.SUCCESS)) {
resultsModel.setSuccessful(true);
} else {
resultsModel.setSuccessful(false);
}
} else { } else {
Paygo24Utils paygo = new Paygo24Utils(); Paygo24Utils paygo = new Paygo24Utils();
String result = paygo.payment(automaticQueueModel.getOrder_phone(), automaticQueueModel.getSegment_id(), automaticQueueModel.getOrder_money()); String result = paygo.payment(automaticQueueModel.getOrder_phone(), automaticQueueModel.getSegment_id(), automaticQueueModel.getOrder_money());
...@@ -157,6 +153,8 @@ public class AutomaticCodeServiceImpl implements AutomaticCodeService { ...@@ -157,6 +153,8 @@ public class AutomaticCodeServiceImpl implements AutomaticCodeService {
} else { } else {
resultsModel.setSuccessful(false); resultsModel.setSuccessful(false);
} }
resultsModel.setTopUpNum(orderNumId);
} }
return resultsModel; return resultsModel;
......
...@@ -10,9 +10,7 @@ import javax.xml.datatype.DatatypeFactory; ...@@ -10,9 +10,7 @@ import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar; import javax.xml.datatype.XMLGregorianCalendar;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.*;
import java.util.GregorianCalendar;
import java.util.Random;
/** /**
* Created by Administrator on 2018\10\31 0031. * Created by Administrator on 2018\10\31 0031.
...@@ -43,5 +41,70 @@ public class ylmTest { ...@@ -43,5 +41,70 @@ public class ylmTest {
System.out.println(MD5Util.MD5Encode("123456","")); System.out.println(MD5Util.MD5Encode("123456",""));
System.out.println(MD5Util.MD5Encode("123456","utf-8")); System.out.println(MD5Util.MD5Encode("123456","utf-8"));
System.out.println(new Random().nextInt(10000)); System.out.println(new Random().nextInt(10000));
System.out.println("--------");
System.out.println(getCurrentTime());
System.out.println(getFormatedDateString(7));
}
public static String getCurrentTime(){
//获取指定格式的时间
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(TimeZone.getTimeZone("GMT-7"));//指定时区
return sdf.format(new Date());
}
/**
* 取北京时间
* @return
*/
public static String getBeijingTime(){
return getFormatedDateString(8);
}
/**
* 取班加罗尔时间
* @return
*/
public static String getBangaloreTime(){
return getFormatedDateString(5.5f);
}
/**
* 取纽约时间
* @return
*/
public static String getNewyorkTime(){
return getFormatedDateString(-5);
}
/**
* 此函数非原创,从网上搜索而来,timeZoneOffset原为int类型,为班加罗尔调整成float类型
* timeZoneOffset表示时区,如中国一般使用东八区,因此timeZoneOffset就是8
* @param timeZoneOffset
* @return
*/
public static String getFormatedDateString(float timeZoneOffset){
if (timeZoneOffset > 13 || timeZoneOffset < -12) {
timeZoneOffset = 0;
}
int newTime=(int)(timeZoneOffset * 60 * 60 * 1000);
TimeZone timeZone;
String[] ids = TimeZone.getAvailableIDs(newTime);
if (ids.length == 0) {
timeZone = TimeZone.getDefault();
} else {
timeZone = new SimpleTimeZone(newTime, ids[0]);
}
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
sdf.setTimeZone(timeZone);
return sdf.format(new Date());
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment