| @@ -27,8 +27,20 @@ public class BApplication { | |||
| @Value("${fm.open}") | |||
| private boolean fmOpen; | |||
| //@Value("${fm.pos_url}") | |||
| //private String fmPosUrl; | |||
| @Value("${fm.upload_dir}") | |||
| private String uploadDir; | |||
| @Value("${pos.dev_id}") | |||
| private String posDevId; | |||
| @Value("${pos.req_key}") | |||
| private String posReqKey; | |||
| @Value("${pos.res_key}") | |||
| private String posResKey; | |||
| @Value("${pos.url}") | |||
| private String posUrl; | |||
| @Bean | |||
| public boolean isFmException() { | |||
| @@ -45,10 +57,30 @@ public class BApplication { | |||
| return fmOpen; | |||
| } | |||
| //@Bean | |||
| //public String fmPosUrl() { | |||
| // return fmPosUrl; | |||
| //} | |||
| @Bean | |||
| public String fmUploadDir() { | |||
| return uploadDir; | |||
| } | |||
| @Bean | |||
| public String posDevId() { | |||
| return posDevId; | |||
| } | |||
| @Bean | |||
| public String posReqKey() { | |||
| return posReqKey; | |||
| } | |||
| @Bean | |||
| public String posResKey() { | |||
| return posResKey; | |||
| } | |||
| @Bean | |||
| public String posUrl() { | |||
| return posUrl; | |||
| } | |||
| public static void main(String[] args) { | |||
| @@ -0,0 +1,66 @@ | |||
| package com.iformall.controller; | |||
| import com.iformall.common.Result; | |||
| import com.iformall.common.ResultData; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.utils.PosUtil; | |||
| import io.swagger.annotations.Api; | |||
| import io.swagger.annotations.ApiOperation; | |||
| import org.slf4j.Logger; | |||
| import org.slf4j.LoggerFactory; | |||
| import org.springframework.beans.factory.annotation.Autowired; | |||
| import org.springframework.web.bind.annotation.*; | |||
| import java.util.Map; | |||
| @RestController | |||
| @RequestMapping("/api/pos") | |||
| @Api(description = "卡券相关接口") | |||
| public class WxPosController extends BaseController { | |||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||
| @Autowired | |||
| private String posDevId; | |||
| @Autowired | |||
| private String posReqKey; | |||
| @Autowired | |||
| private String posResKey; | |||
| @Autowired | |||
| private String posUrl; | |||
| PosUtil posUtil = new PosUtil(); | |||
| @ApiOperation(value = "检查POSServer是否正常", notes = "") | |||
| @GetMapping("checkAvaiable") | |||
| public ResultData checkAvaiable() { | |||
| try { | |||
| String resStr = posUtil.checkPosMemServer(posUrl); | |||
| if (resStr != null) { | |||
| return new ResultData(); | |||
| } else { | |||
| return new ResultData(Result.ERROR, "无返回值"); | |||
| } | |||
| } catch (MallinkException e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(e.getErrorCode(), e.getMessage()); | |||
| } catch (Exception e) { | |||
| logger.error(e.getMessage()); | |||
| return new ResultData(Result.ERROR, e.getMessage()); | |||
| } | |||
| } | |||
| @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(); | |||
| } | |||
| } | |||
| @@ -31,6 +31,7 @@ public class PosUtil { | |||
| private static final String resKey = "ugPAM7wd&%p6I0W8"; | |||
| // url | |||
| private static final String URL_Version = "/version"; | |||
| private static final String URL_CheckUserPassword = "/checkUserPassword"; | |||
| private static final String URL_GetPosMemConfig = "/getPosMemConfig"; | |||
| private static final String URL_GetQrCode = "/getQrCode"; | |||
| @@ -89,6 +90,19 @@ public class PosUtil { | |||
| } | |||
| return result; | |||
| } | |||
| private String doGet(String url) { | |||
| String result = null; | |||
| HttpUrl reqUrl = HttpUrl.parse(url).newBuilder().build(); | |||
| Request request = new Request.Builder().url(reqUrl).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>")) { | |||
| @@ -98,6 +112,21 @@ public class PosUtil { | |||
| } | |||
| /** | |||
| * 0. 检查POS会员server是否正常 | |||
| * @param baseUrl | |||
| * @return B端用户信息 | |||
| */ | |||
| public String checkPosMemServer(String baseUrl) throws MallinkException { | |||
| String respStr = doGet(baseUrl + URL_Version); | |||
| if(respStr == null) { | |||
| throw new MallinkException(ErrorCode.POS_CMD_FAIL); | |||
| } | |||
| if(checkRespFailed(respStr)) { | |||
| throw new MallinkException(ErrorCode.POS_CMD_FAIL); | |||
| } | |||
| return respStr; | |||
| } | |||
| /** | |||
| * 1. 商户POS用户/B端用户登录检查 | |||
| * @param baseUrl | |||
| @@ -490,6 +519,12 @@ public class PosUtil { | |||
| String verifyType = "independent"; | |||
| PosUtil posUtil = new PosUtil(); | |||
| String resStr = posUtil.checkPosMemServer(domain); | |||
| if (resStr != null) { | |||
| System.out.println(resStr); | |||
| } | |||
| /* | |||
| String resStr = posUtil.checkUserPassword(domain, devId, reqKey, tenantId, phone, password); | |||
| if (resStr != null) { | |||
| System.out.println(resStr); | |||
| @@ -501,7 +536,6 @@ public class PosUtil { | |||
| System.out.println("verify sign ok"); | |||
| } | |||
| } | |||
| /* | |||
| resStr = posUtil.getPosMemConfig(domain, devId, reqKey, tenantId); | |||
| if (resStr != null) { | |||
| System.out.println(resStr); | |||
| @@ -108,7 +108,13 @@ fm: | |||
| deploy: 1 | |||
| open: true | |||
| upload_dir: /home/test/server/uploads | |||
| pos_url: https://pos.youlane.cn/api | |||
| pos: | |||
| dev_id: fmpos | |||
| url: https://pos.youlane.cn/api | |||
| req_key: ZiGFLC4@3c5sTLZT | |||
| res_key: ugPAM7wd&%p6I0W8 | |||
| logging: | |||
| level: | |||
| @@ -93,6 +93,12 @@ fm: | |||
| open: true | |||
| upload_dir: /home/ec2-user/server/uploads/ | |||
| pos: | |||
| dev_id: fmpos | |||
| url: https://pos.malls.iformall.com/api | |||
| req_key: ZiGFLC4@3c5sTLZT | |||
| res_key: ugPAM7wd&%p6I0W8 | |||
| logging: | |||
| level: | |||
| tk.mybatis: debug | |||
| @@ -93,6 +93,12 @@ fm: | |||
| open: true | |||
| upload_dir: /home/ec2-user/server/uploads/ | |||
| pos: | |||
| dev_id: fmpos | |||
| url: https://postest.malls.iformall.com/api | |||
| req_key: ZiGFLC4@3c5sTLZT | |||
| res_key: ugPAM7wd&%p6I0W8 | |||
| logging: | |||
| level: | |||
| tk.mybatis: debug | |||