public String wxH5Sign(String merNo, String pkgCode, String plan_id,String contractOuterid, RequestHandler requestHandler, String returnUrl, String clientip) {
try {
List<ConfigEntity> configEntityList = configService.findList(merNo, pkgCode);
MainEntity merchantMainEntity = mainService.find(configEntityList.get(0).getProviderCode(), configEntityList.get(0).getMainNo());
WxMerchantEntity wxMerchantEntity = wxMerchantService.queryWxMerchantInfo(merchantMainEntity.getMainNo());
String appid = wxMerchantEntity.getAppId();
String mch_id = wxMerchantEntity.getPartner();
String contract_code = orderNoService.getContractCode();
String request_serial = orderNoService.getRequestSerial();
String contract_display_account = "正隆保险";
String orderNo = orderNoService.getOrderNo();
String notify_url = "https://testpp.bxlsj.com/sign/wechat/callback/" + orderNo;
String version = "1.0";
String timestamp = String.valueOf(System.currentTimeMillis() / 1000);
SortedMap<String, String> packageParams = new TreeMap<>();
packageParams.put("appid", appid);
packageParams.put("mch_id", mch_id);
packageParams.put("plan_id", plan_id);
packageParams.put("contract_code", contract_code);
packageParams.put("request_serial", request_serial);
packageParams.put("contract_display_account", contract_display_account);
packageParams.put("notify_url", notify_url);
packageParams.put("version", version);
packageParams.put("timestamp", timestamp);
packageParams.put("clientip", clientip);
packageParams.put("outerid", contractOuterid);
requestHandler.init(appid, wxMerchantEntity.getAppsecret(), wxMerchantEntity.getPartnerkey());
String sign = requestHandler.createHmacSign(packageParams);
notify_url = URLEncoder.encode(notify_url);
String url = "https://api.mch.weixin.qq.com/papay/h5entrustweb?appid=" + appid
+ "&contract_code=" + contract_code + "&contract_display_account="
+ contract_display_account + "&mch_id=" + mch_id + "¬ify_url=" +
notify_url + "&plan_id=" + plan_id + "&request_serial=" + request_serial + "&clientip=" + clientip
+ "×tamp=" + timestamp + "&version=" + version + "&sign=" + sign+"&outerid="+contractOuterid;
log.info("wxH5Sign H5纯签约 merNo:[{}],pkgCode:[{}] url[{}]", merNo, pkgCode, url);
return url;
} catch (Exception e) {
log.error("wxH5Sign H5纯签约 merNo:[{}],pkgCode:[{}] clientip[{}]", merNo, pkgCode, clientip);
}
return null;
}
public String createHmacSign(SortedMap<String, String> packageParams) throws Exception {
StringBuffer sb = new StringBuffer();
Set es = packageParams.entrySet();
Iterator it = es.iterator();
while (it.hasNext()) {
Map.Entry entry = (Map.Entry) it.next();
String k = (String) entry.getKey();
String v = (String) entry.getValue();
if (null != v && !"".equals(v) && !"sign".equals(k)
&& !"key".equals(k)) {
sb.append(k + "=" + v + "&");
}
}
return WXPayUtil.HMACSHA256(sb.toString(),this.key);
}
public static String HMACSHA256(String data, String key) throws Exception {
Mac sha256_HMAC = Mac.getInstance("HmacSHA256");
SecretKeySpec secret_key = new SecretKeySpec(key.getBytes("UTF-8"), "HmacSHA256");
sha256_HMAC.init(secret_key);
byte[] array = sha256_HMAC.doFinal(data.getBytes("UTF-8"));
StringBuilder sb = new StringBuilder();
for (byte item : array) {
sb.append(Integer.toHexString((item & 0xFF) | 0x100).substring(1, 3));
}
return sb.toString().toUpperCase();
}