package com.cy.demo.manager.huafeiduo;
import com.modules.api.utils.FastJsonUtil;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;
import java.util.TreeMap;
/**
* @author 话费多集成
* @date 2019/4/119:31
*/
public class Hfeiduo {
private static String _api_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private static String _secret_key = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx";
private static String _notify_url = "http://yourdomain.com/callback/huafeiduo";
/**
* 获得签名
*
* @param treeMap
* @return
*/
public static String _getSign(TreeMap<String, String> treeMap) {
StringBuffer sb = new StringBuffer();
for (Map.Entry<String, String> e : treeMap.entrySet()) {
sb.append(e.getKey() + e.getValue());
}
System.out.println();
return UrlUtil.encrypt32(sb.append(_secret_key).toString());
}
/**
* 检查是否可充值
*
* @param card_worth
* @param phone_number
* @return
*/
public static Map check(String card_worth, String phone_number) {
TreeMap treeMap = new TreeMap();
treeMap.put("card_worth", card_worth);
treeMap.put("phone_number", phone_number);
treeMap.put("api_key", _api_key);
treeMap.put("sign", _getSign(treeMap));
String pream = UrlUtil.buildMap(treeMap);
String s = HttpUtils.sendGet("http://api.huafeiduo.com/?mod=order.phone.check", pream);
Map<String, Object> map = FastJsonUtil.json2Map(s);
return map;
}
/**
* 提交订单
*
* @param card_worth
* @param phone_number
* @param sp_order_id
*/
public static Map submit(String card_worth, String phone_number, String sp_order_id) {
TreeMap treeMap = new TreeMap();
treeMap.put("card_worth", card_worth);
treeMap.put("phone_number", phone_number);
treeMap.put("notify_url", _notify_url);
//系统订单,自己生成
treeMap.put("sp_order_id", sp_order_id);
treeMap.put("api_key", _api_key);
treeMap.put("sign", _getSign(treeMap));
String pream = UrlUtil.buildMap(treeMap);
String s = HttpUtils.sendGet("http://api.huafeiduo.com/gateway.cgi?mod=order.phone.submit", pream);
Map<String, Object> map = FastJsonUtil.json2Map(s);
if (map.get("status").equals("success")) {
System.out.println("充值成功!");
}
return map;
}
/**
* 获得余额
*
* @return
*/
public static String getBalance() {
TreeMap treeMap = new TreeMap();
treeMap.put("api_key", _api_key);
treeMap.put("sign", _getSign(treeMap));
String pream = UrlUtil.buildMap(treeMap);
String s = HttpUtils.sendGet("http://api.huafeiduo.com/gateway.cgi?mod=account.balance", pream);
Map<String, Object> map = FastJsonUtil.json2Map(s);
BigDecimal b = (BigDecimal) ((Map) map.get("data")).get("balance");
return b.toString();
}
/**
* 订单状态
* order_status = init(订单初始化) | recharging(充值中) | success(充值成功) | failure(充值失败)
*
* @param sp_order_id
* @return
*/
public static String getRechargeStateByOrderId(String sp_order_id) {
TreeMap treeMap = new TreeMap();
treeMap.put("sp_order_id", sp_order_id);
treeMap.put("api_key", _api_key);
treeMap.put("sign", _getSign(treeMap));
String pream = UrlUtil.buildMap(treeMap);
String s = HttpUtils.sendGet("http://api.huafeiduo.com/gateway.cgi?mod=order.phone.status", pream);
Map<String, Object> map = FastJsonUtil.json2Map(s);
if (map.get("status").equals("success")) {
Map data = (Map) map.get("data");
String order_status = (String) data.get("order_status");
System.out.println("订单状态==>");
System.out.println(order_status);
return order_status;
}
return (String) map.get("message");
}
/**
* 订单信息
*
* @param sp_order_id
* @return
*/
public static Map<String, Object> getOrderDetailByOrderId(String sp_order_id) {
TreeMap treeMap = new TreeMap();
treeMap.put("sp_order_id", sp_order_id);
treeMap.put("api_key", _api_key);
treeMap.put("sign", _getSign(treeMap));
String pream = UrlUtil.buildMap(treeMap);
String s = HttpUtils.sendGet("http://api.huafeiduo.com/gateway.cgi?mod=order.phone.get", pream);
String s1 = UrlUtil.unicodeToString(s);
Map<String, Object> map = FastJsonUtil.json2Map(s1);
Map<String, Object> data = (Map<String, Object>) map.get("data");
if(data!=null){
return data;
}else {
data = new HashMap<>();
data.put("message",map.get("message"));
}
return data;
}
public static Map sendSubmit(String card_worth, String phone_number, String sp_order_id){
Map check = check(card_worth, phone_number);
if(!check.get("status").equals("success")){
return check;
}
Map submit = submit(card_worth, phone_number, sp_order_id);
return submit;
}
public static void main(String[] args) {
// if(check("100", "13725290116")){
// submit("1","13725290116", UUIDUtils.getUUID());
// }
//
// System.out.println( getBalance());
//
//System.out.println(getRechargeStateByOrderId("0cf64a83caa64893b2034f4b714369e8"));
Map<String, Object> orderDetailByOrderId = getOrderDetailByOrderId("2019042414295227591");
System.out.println(orderDetailByOrderId);
}
}
java集成话费多sdk
©著作权归作者所有,转载或内容合作请联系作者
- 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
- 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
- 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
推荐阅读更多精彩内容
- 项目上线期,加上公司原有未配置热更新的Cocos2d / Unity游戏项目的日常更新,工作中遇到了不少多SDK接...
- 一、 实现Runnable 接口,并实现该接口的 run() 方法。 通过实现Runnable接口的类,就是产生一...