dev-discount
袁野 3 years ago
parent 6127d31e2c
commit c2bed49a7d
  1. 27
      hai-service/src/main/java/com/hai/common/utils/WxUtils.java
  2. 22
      hai-service/src/main/java/com/hai/service/impl/HighTestServiceImpl.java

@ -249,6 +249,33 @@ public class WxUtils {
} }
public static String generateSignatureAppSecret(final Map<String, Object> data, String key, WXPayConstants.SignType signType) throws Exception {
Set<String> keySet = data.keySet();
String[] keyArray = keySet.toArray(new String[keySet.size()]);
Arrays.sort(keyArray);
StringBuilder sb = new StringBuilder();
for (String k : keyArray) {
if (k.equals(WXPayConstants.FIELD_SIGN)) {
continue;
}
if (StringUtils.isBlank(sb.toString())) {
sb.append(k).append("=").append(data.get(k));
} else {
sb.append("&").append(k).append("=").append(data.get(k));
}
}
sb.append("&app_secret=").append(key);
if (WXPayConstants.SignType.MD5.equals(signType)) {
return MD5(sb.toString() , false);
}
else if (WXPayConstants.SignType.HMACSHA256.equals(signType)) {
return HMACSHA256(sb.toString(), key);
}
else {
throw new Exception(String.format("Invalid sign_type: %s", signType));
}
}
public static String generateSignature(final Map<String, Object> data) throws Exception { public static String generateSignature(final Map<String, Object> data) throws Exception {
Set<String> keySet = data.keySet(); Set<String> keySet = data.keySet();
String[] keyArray = keySet.toArray(new String[keySet.size()]); String[] keyArray = keySet.toArray(new String[keySet.size()]);

@ -6,10 +6,7 @@ import com.hai.common.exception.ErrorCode;
import com.hai.common.exception.ErrorHelp; import com.hai.common.exception.ErrorHelp;
import com.hai.common.exception.SysCode; import com.hai.common.exception.SysCode;
import com.hai.common.pay.util.sdk.WXPayConstants; import com.hai.common.pay.util.sdk.WXPayConstants;
import com.hai.common.utils.DateUtil; import com.hai.common.utils.*;
import com.hai.common.utils.HttpsUtils;
import com.hai.common.utils.RedisUtil;
import com.hai.common.utils.WxUtils;
import com.hai.dao.HighUserEtcMapper; import com.hai.dao.HighUserEtcMapper;
import com.hai.entity.HighDiscountAgentCode; import com.hai.entity.HighDiscountAgentCode;
import com.hai.entity.HighUser; import com.hai.entity.HighUser;
@ -142,20 +139,21 @@ public class HighTestServiceImpl implements HighTestService {
@Override @Override
public JSONObject getMobile(String phone) throws Exception { public JSONObject getMobile(String phone) throws Exception {
String timestamp = String.valueOf(System.currentTimeMillis());
Map<String , Object> map = new HashMap<>(); Map<String , Object> map = new HashMap<>();
map.put("mobile" , "18090580471"); map.put("mobile" , "18090580471");
map.put("amount" , "0.01"); map.put("amount" , "30");
map.put("out_order_id" , "CZ20220110895732352345"); map.put("out_order_id" , "CZ" + DateUtil.date2String(new Date(),"yyyyMMddHHmmss") + IDGenerator.nextId(5));
map.put("app_key" , "kg5n9br7evt4q8lp"); map.put("app_key" , "eaomqcbpdz7yjfih");
map.put("timestamp" , DateUtil.date2String(new Date(),"yyyyMMddHHmmss")); map.put("timestamp" , timestamp.substring(0,timestamp.length()-3));
map.put("is_fast" , "1"); map.put("is_fast" , "1");
map.put("notify_url" , "https://hsgcs.dctpay.com/crest/czOrder/orderRefundNotify"); map.put("notify_url" , "https://hsgcs.dctpay.com/crest/czOrder/orderRefundNotify");
StringBuilder signStr = new StringBuilder(WxUtils.generateSignature(map)); String signStr = WxUtils.generateSignatureAppSecret(map, "xkf9eoq2cjh6uvzp0mtrga134lnibdw8" , WXPayConstants.SignType.MD5);
map.put("sign" , WxUtils.MD5(String.valueOf(signStr.append("key=kg5n9br7evt4q8lp")),true)); map.put("sign" , signStr);
JSONObject object = HttpsUtils.doPost("https://hfcs.dmjvip.com/index.php/third/mobile/createOrder" , map); return HttpsUtils.doPost("https://hfcs.dmjvip.com/index.php/third/mobile/createOrder" , map);
return object;
} }
} }

Loading…
Cancel
Save