| @@ -20,14 +20,16 @@ public class PasswordHelper { | |||||
| } | } | ||||
| /* | |||||
| public static void main(String[] args) { | public static void main(String[] args) { | ||||
| MallUserInfo user = new MallUserInfo(); | MallUserInfo user = new MallUserInfo(); | ||||
| user.setUsername("fmkjadmin"); | |||||
| user.setPassword("fmkjadmin790"); | |||||
| user.setUsername("admin"); | |||||
| user.setPassword("admin123"); | |||||
| PasswordHelper passwordHelper = new PasswordHelper(); | PasswordHelper passwordHelper = new PasswordHelper(); | ||||
| passwordHelper.encryptPassword(user); | passwordHelper.encryptPassword(user); | ||||
| System.out.println(user); | System.out.println(user); | ||||
| System.out.println(user.getPassword()); | System.out.println(user.getPassword()); | ||||
| } | } | ||||
| */ | |||||
| } | } | ||||
| @@ -189,4 +189,15 @@ public class WxCouponOrderController extends BaseController { | |||||
| } | } | ||||
| return new ResultData(Result.SUCCESS, "查询成功", wxCouponOrderService.getById(couponOrderId)); | return new ResultData(Result.SUCCESS, "查询成功", wxCouponOrderService.getById(couponOrderId)); | ||||
| } | } | ||||
| @ApiOperation(value = "核销接口", notes = "{\"couponOrderId\":\"string\"}") | |||||
| @PostMapping("verifyForPos") | |||||
| public ResultData verifyForPos(@RequestBody Map<String, String> paramMap) { | |||||
| // 0. 获取dev信息, tenantId信息 | |||||
| // 1. check 查询 | |||||
| // 2. create order | |||||
| // 3. 独立核销 | |||||
| return new ResultData(); | |||||
| } | |||||
| } | } | ||||
| @@ -0,0 +1,106 @@ | |||||
| 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; | |||||
| import com.iformall.pay.WxPayConstant; | |||||
| import com.iformall.pay.WxPayment; | |||||
| import okhttp3.*; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| 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; | |||||
| /** | |||||
| * @Title: POS接口 | |||||
| * @author: Stormeye | |||||
| * @date: 2018/3/8 17:41 | |||||
| * @version: V1.0 | |||||
| */ | |||||
| public class PosUtil { | |||||
| private static final Logger logger = LoggerFactory.getLogger(PosUtil.class); | |||||
| private static final String domain = "https://pos.youlane.cn/api"; | |||||
| private static final String devId = "fmpos"; | |||||
| private static final String reqKey = "ZiGFLC4@3c5sTLZT"; | |||||
| private static final String resKey = "ugPAM7wd&%p6I0W8"; | |||||
| // url | |||||
| private static final String checkUserPassword = "/checkUserPassword"; | |||||
| private static final String getPosMemConfig = "/getPosMemConfig"; | |||||
| private final OkHttpClient client = new OkHttpClient(); | |||||
| private String doPost(String url, Map<String, String> paramMap) { | |||||
| String result = null; | |||||
| FormBody.Builder builder = new FormBody.Builder(); | |||||
| 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); | |||||
| } | |||||
| RequestBody body = builder.build(); | |||||
| Request request = new Request.Builder() | |||||
| .url(url) | |||||
| .post(body) | |||||
| .build(); | |||||
| Response response = null; | |||||
| try { | |||||
| response = client.newCall(request).execute(); | |||||
| result = response.body().string(); | |||||
| } catch (IOException e) { | |||||
| logger.error(e.getMessage()); | |||||
| } | |||||
| return result; | |||||
| } | |||||
| private boolean checkRespFailed(String resp) { | |||||
| if(resp.startsWith("<html>") || resp.startsWith("<!DOCTYPE html>")) { | |||||
| return true; | |||||
| } | |||||
| return false; | |||||
| } | |||||
| /** | |||||
| * 1. 商户用户登录检查 | |||||
| * @param baseUrl | |||||
| * @param devId | |||||
| * @param reqKey | |||||
| * @return 车场状态查询响应信息 | |||||
| */ | |||||
| 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.TENANT_ID, tenantId); | |||||
| paramMap.put(WxPayConstant.PHONE, phone); | |||||
| paramMap.put(WxPayConstant.PASSWORD, password); | |||||
| paramMap = WxPayment.buildSignAfterParasMapForHMAC(paramMap, resKey); | |||||
| String respStr = doPost(baseUrl + checkUserPassword, paramMap); | |||||
| if(respStr == null) { | |||||
| throw new MallinkException(ErrorCode.POS_CMD_FAIL); | |||||
| } | |||||
| if(checkRespFailed(respStr)) { | |||||
| throw new MallinkException(ErrorCode.POS_CMD_FAIL); | |||||
| } | |||||
| return respStr; | |||||
| } | |||||
| 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); | |||||
| } | |||||
| } | |||||
| @@ -48,6 +48,8 @@ public class PosAppTest { | |||||
| private static final String tenantId = "456"; | private static final String tenantId = "456"; | ||||
| private static final String merchantId = "320833942159982592"; // 东软专用 | private static final String merchantId = "320833942159982592"; // 东软专用 | ||||
| private static final String buUserId = "320834180694245376"; | private static final String buUserId = "320834180694245376"; | ||||
| private static final String phone = "13120223636"; | |||||
| private static final String password = "drpos345"; | |||||
| /* | /* | ||||
| 可用的交易券, 支付可用(1, 2, 6), 独立核销可用(4, 6, 8, 9) | 可用的交易券, 支付可用(1, 2, 6), 独立核销可用(4, 6, 8, 9) | ||||
| @@ -96,6 +98,29 @@ public class PosAppTest { | |||||
| .andDo(MockMvcResultHandlers.print()); | .andDo(MockMvcResultHandlers.print()); | ||||
| } | } | ||||
| @Test | |||||
| public void checkUserPasswordTest() throws Exception { | |||||
| Map<String, String> reqObj = new HashMap<>(); | |||||
| reqObj.put(WxPayConstant.NONCE_STR, "1"); | |||||
| reqObj.put(WxPayConstant.DEV_ID, devId); | |||||
| reqObj.put(WxPayConstant.TENANT_ID, tenantId); | |||||
| reqObj.put(WxPayConstant.PHONE, phone); | |||||
| reqObj.put(WxPayConstant.SIGN, WxPayment.createSignHMAC(reqObj, devReqKey)); | |||||
| String reqJsonStr = JSONObject.toJSONString(reqObj); | |||||
| MvcResult result = mockMvc.perform( | |||||
| MockMvcRequestBuilders.post("/getPosMemConfig") | |||||
| .contentType(MediaType.APPLICATION_JSON) | |||||
| .content(reqJsonStr)) | |||||
| .andExpect(MockMvcResultMatchers.status().isOk()) | |||||
| .andDo(MockMvcResultHandlers.print()) | |||||
| .andReturn(); | |||||
| String responseStr = result.getResponse().getContentAsString(); | |||||
| ObjectMapper mapper = new ObjectMapper(); | |||||
| Map<String,String> respMap = mapper.readValue(responseStr, Map.class); | |||||
| boolean resSigned = WxPayment.verifyNotifyHMAC(respMap, devResKey); | |||||
| System.out.println("response sign: " + resSigned); | |||||
| Assert.assertEquals(resSigned, true); | |||||
| } | |||||
| @Test | @Test | ||||
| public void getPosMemConfigTest() throws Exception { | public void getPosMemConfigTest() throws Exception { | ||||
| Map<String, String> reqObj = new HashMap<>(); | Map<String, String> reqObj = new HashMap<>(); | ||||
| @@ -245,6 +245,8 @@ public enum ErrorCode{ | |||||
| POS_COUPON_ORDER_VERIFY_NOT_CANCEL(11104, "此券核销无法取消"), | POS_COUPON_ORDER_VERIFY_NOT_CANCEL(11104, "此券核销无法取消"), | ||||
| POS_CAR_PAY_NOT_CANCEL(11105, "卡支付无法取消"), | POS_CAR_PAY_NOT_CANCEL(11105, "卡支付无法取消"), | ||||
| POS_CMD_FAIL(11200, "POS命令错误"), | |||||
| /** | /** | ||||
| * 支付 | * 支付 | ||||