
com.hc360.hcpay.payment.util.HFBUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of payment-util Show documentation
Show all versions of payment-util Show documentation
hcpay payment-util java sdk
The newest version!
package com.hc360.hcpay.payment.util;
import java.util.HashMap;
import java.util.Map;
import com.alibaba.fastjson.JSONObject;
import com.hc360.hcpay.payment.config.HCPayConfig;
import com.hc360.hcpay.payment.sign.SignVerifyFactory;
public class HFBUtil {
/**
* ??url?????????õ?map??ʽ????Ӧ
* 1 ??????????ǩ??
* 2 ????Ӧ?е?ǩ????????֤
*
* @param url
* @param request
* @return
* @throws Exception
*/
public static Map sendRequest(String url,
Map request) throws Exception {
if (request.get("charet") == null)
request.put("charset", HCPayConfig.input_charset);
if (request.get("signType") == null)
request.put("signType", HCPayConfig.sign_type.name());
if(request.get("service")==null)
request.put("service", "create_direct_pay_by_user");
if(request.get("version")==null)
request.put("version", "V1.0");
request.put("partner", HCPayConfig.partner);
return new HFBUtil().sendRequestInner(url, request);
}
/**
* ??url?????????õ?map??ʽ????Ӧ
* 1 ??ԭʼ????????ǩ??
* 2 ????Ӧ?е?ǩ????????֤
*
* @param url
* @param request
* @return
* @throws Exception
* ???ǩ????֤ʧ?ܡ????????쳣????ֱ???׳??쳣
*/
Map sendRequestInner(String url, Map request)
throws Exception {
String jsonResult = HCPaySubmit.buildRequest(url, "", "", request);
if (jsonResult == null)
throw new Exception("response is null??");
/**
* ????Ӧ???תΪmap
*/
Map response = jsonToMap(jsonResult);
// ??ȡ??ǩ???ַ???
String str2Sign = HCPayCore.createLinkString(HCPayCore
.paraFilter(response));
String sign = response.get("sign");
// ǩ????֤
boolean isSignValid = SignVerifyFactory.createSignAndVerify(
HCPayConfig.sign_type).verify(str2Sign, sign, HCPayConfig.key,
response.get("charset"));
if (!isSignValid)
throw new Exception("sign validation failed??");
return response;
}
Map jsonToMap(String jsonStr) {
JSONObject jsonObj = (JSONObject) JSONObject.parse(jsonStr);
Map map = new HashMap();
for (String key : jsonObj.keySet())
map.put(key, jsonObj.getString(key));
return map;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy