|
|
|
@@ -1,7 +1,6 @@ |
|
|
|
package com.iformall.utils; |
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSON; |
|
|
|
import com.alibaba.fastjson.JSONArray; |
|
|
|
import com.alibaba.fastjson.JSONObject; |
|
|
|
import com.iformall.common.ErrorCode; |
|
|
|
import com.iformall.exception.MallinkException; |
|
|
|
@@ -13,10 +12,6 @@ import org.slf4j.Logger; |
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
|
|
|
|
import java.io.IOException; |
|
|
|
import java.math.BigDecimal; |
|
|
|
import java.security.MessageDigest; |
|
|
|
import java.time.LocalDateTime; |
|
|
|
import java.time.format.DateTimeFormatter; |
|
|
|
import java.util.HashMap; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
@@ -41,19 +36,20 @@ public class PosUtil { |
|
|
|
private final OkHttpClient client = new OkHttpClient(); |
|
|
|
private String doPost(String url, Map<String, String> paramMap) { |
|
|
|
String result = null; |
|
|
|
FormBody.Builder builder = new FormBody.Builder(); |
|
|
|
MediaType jsonType = MediaType.parse("application/json; charset=utf-8"); |
|
|
|
JSONObject json = new JSONObject(); |
|
|
|
for (Map.Entry<String, String> entry: paramMap.entrySet()) { |
|
|
|
String key = entry.getKey(); |
|
|
|
String value = entry.getValue(); |
|
|
|
// 略过空值 |
|
|
|
if (StringUtils.isBlank(value)) |
|
|
|
continue; |
|
|
|
builder.add(key, value); |
|
|
|
json.put(key, value); |
|
|
|
} |
|
|
|
RequestBody body = builder.build(); |
|
|
|
RequestBody requestBody = RequestBody.create(jsonType, JSON.toJSONString(json)); |
|
|
|
Request request = new Request.Builder() |
|
|
|
.url(url) |
|
|
|
.post(body) |
|
|
|
.post(requestBody) |
|
|
|
.build(); |
|
|
|
Response response = null; |
|
|
|
try { |
|
|
|
@@ -83,10 +79,11 @@ public class PosUtil { |
|
|
|
public String checkUserPassword(String baseUrl, String devId, String reqKey, String resKey, |
|
|
|
String tenantId, String phone, String password) throws MallinkException { |
|
|
|
Map<String, String> paramMap = new HashMap<>(); |
|
|
|
paramMap.put(WxPayConstant.DEV_ID, devId); |
|
|
|
paramMap.put(WxPayConstant.TENANT_ID, tenantId); |
|
|
|
paramMap.put(WxPayConstant.PHONE, phone); |
|
|
|
paramMap.put(WxPayConstant.PASSWORD, password); |
|
|
|
paramMap = WxPayment.buildSignAfterParasMapForHMAC(paramMap, resKey); |
|
|
|
paramMap = WxPayment.buildSignAfterParasMapForHMAC(paramMap, reqKey); |
|
|
|
|
|
|
|
String respStr = doPost(baseUrl + checkUserPassword, paramMap); |
|
|
|
if(respStr == null) { |
|
|
|
@@ -101,6 +98,15 @@ public class PosUtil { |
|
|
|
public static void main(String[] args) { |
|
|
|
PosUtil posUtil = new PosUtil(); |
|
|
|
String resStr = posUtil.checkUserPassword(domain, devId, reqKey, resKey, "456", "13120223636", "drpos345"); |
|
|
|
System.out.println(resStr); |
|
|
|
if (resStr != null) { |
|
|
|
System.out.println(resStr); |
|
|
|
JSONObject retObj = JSON.parseObject(resStr); |
|
|
|
Map options = retObj; |
|
|
|
if (!WxPayment.verifyNotifyHMAC(options, resKey)) { |
|
|
|
System.out.println("verify sign error"); |
|
|
|
} else { |
|
|
|
System.out.println("verify sign ok"); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |