| @@ -80,6 +80,17 @@ public class DataTowerController extends BaseController { | |||
| return new ResultData(data); | |||
| } | |||
| @ApiOperation("新版本查询客流") | |||
| @GetMapping("/queryCustomerNewVersion") | |||
| @SystemControllerLog(description = "数据塔台-新版本查询客流") | |||
| public ResultData queryCustomerNewVersion() { | |||
| logger.debug("[" + getIpAddr() + "] DataTowerController::queryCustomerNewVersion"); | |||
| Map<String, Object> data = dataTowerService.queryCustomerNewVersion(getTenantInfo()); | |||
| return new ResultData(data); | |||
| } | |||
| @ApiOperation("查询客流") | |||
| @GetMapping("/queryCustomerData") | |||
| @@ -38,3 +38,6 @@ CREATE TABLE `wx_mall_ocr_model` ( | |||
| ALTER TABLE `wx_wiwide_info` ADD COLUMN `user_name` VARCHAR(100) COMMENT '登陆账号,首次初始化wiwideId和key用'; | |||
| ALTER TABLE `wx_wiwide_info` ADD COLUMN `password` VARCHAR(100) COMMENT '登陆密码'; | |||
| ALTER TABLE `wx_wiwide_info` ADD COLUMN `old_plat` int(1) NOT NULL DEFAULT 0 COMMENT '是否是老平台 0-老平台 1-新平台'; | |||
| ALTER TABLE `wx_wiwide_info` ADD COLUMN `sign_key` VARCHAR(100) COMMENT '加密key,新版本接口需要' AFTER `wiwide_key`; | |||
| @@ -89,7 +89,8 @@ public class FormallTess4jTrain { | |||
| public static String getTrainSteps(String lang,String fontName) { | |||
| StringBuffer sb = new StringBuffer("请进入到样本图片文件夹用doc命令执行.").append(huanhangstr); | |||
| StringBuffer sb = new StringBuffer("请先安装tess4j(4.0以上),配置好环境变量. 下载jTessBoxEditor(用于训练,带FX的支持中文)").append(huanhangstr); | |||
| sb.append("请进入到样本图片文件夹用doc命令执行.").append(huanhangstr); | |||
| sb.append("第一步,用jTessBoxEditor --> Tools --> Merge 多选图片,保存为tif格式 .命名格式为[lang].[fontName].exp0.tif. 命名:").append(lang).append(".").append(fontName).append(".exp0.tif ").append(huanhangstr); | |||
| sb.append("............ ").append(huanhangstr); | |||
| sb.append("第二步,用tif生成box ").append(huanhangstr); | |||
| @@ -20,6 +20,9 @@ public class WxWiWideInfo extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="迈外迪key",name="wiwideKey") | |||
| private String wiwideKey; | |||
| @io.swagger.annotations.ApiModelProperty(value="加密key,新版本接口需要",name="signKey") | |||
| private String signKey; | |||
| @io.swagger.annotations.ApiModelProperty(value="登陆username",name="userName") | |||
| private String userName; | |||
| @@ -37,5 +40,8 @@ public class WxWiWideInfo extends TenantEntity { | |||
| @io.swagger.annotations.ApiModelProperty(value="迈外迪信息类型列表,1,支持客流 2,支持wifi",name="capability") | |||
| private String capability; | |||
| @io.swagger.annotations.ApiModelProperty(value="是否是老平台 0-老平台 1-新平台",name="oldPlat") | |||
| private Integer oldPlat; | |||
| } | |||
| @@ -11,5 +11,7 @@ public interface WxWiwideInfoMapper extends CommonMapper<WxWiWideInfo, Long> { | |||
| void updateToken(WxWiWideInfo wxWiWideInfo); | |||
| void updateSercret(WxWiWideInfo wxWiWideInfo); | |||
| } | |||
| @@ -16,6 +16,8 @@ public interface DataTowerService { | |||
| Map<String,Object> queryCar(TenantEntity tenantEntity); | |||
| Map<String,Object> queryCustomer(TenantEntity tenantEntity); | |||
| Map<String,Object> queryCustomerNewVersion(TenantEntity tenantEntity); | |||
| ResultData queryCustomerData(TenantEntity tenantEntity, Map<String, String> params); | |||
| @@ -15,7 +15,8 @@ import com.iformall.service.DataTowerService; | |||
| import com.iformall.service.WxCUserCarService; | |||
| import com.iformall.service.WxCouponChannelService; | |||
| import com.iformall.service.WxCouponOrderService; | |||
| import com.iformall.sms.wiwide.WiwideToken; | |||
| import com.iformall.sms.wiwide.WiwideEntry; | |||
| import com.iformall.sms.wiwide.WiwideSercret; | |||
| import com.iformall.sms.wiwide.WiwideUtil; | |||
| import com.iformall.utils.DateUtils; | |||
| import org.apache.commons.lang3.StringUtils; | |||
| @@ -782,6 +783,23 @@ public class DataTowerServiceImpl implements DataTowerService { | |||
| } | |||
| return datamap; | |||
| } | |||
| @Override | |||
| public Map<String, Object> queryCustomerNewVersion(TenantEntity tenantEntity) { | |||
| WxWiWideInfo wiWideInfo = new WxWiWideInfo(); | |||
| wiWideInfo.updateTenantInfo(tenantEntity); | |||
| List<WxWiWideInfo> list = wxWiwideInfoMapper.findList(wiWideInfo); | |||
| Map<String, Object> datamap = new HashMap<>(2); | |||
| if(list.size()>0){ | |||
| wiWideInfo = list.get(0); | |||
| String wiwideUrl = wiWideInfo.getWiwideUrl(); | |||
| datamap.put("token", getWiwideSercret(wiWideInfo)); | |||
| datamap.put("sign", WiwideEntry.encrypt(wiWideInfo)); | |||
| datamap.put("url", wiwideUrl); | |||
| datamap.put("capability", wiWideInfo.getCapability()); | |||
| } | |||
| return datamap; | |||
| } | |||
| private void updateToken(WxWiWideInfo wiWideInfo, String token) { | |||
| Calendar instance = Calendar.getInstance(); | |||
| @@ -799,6 +817,20 @@ public class DataTowerServiceImpl implements DataTowerService { | |||
| logger.info("更新TOKEN失败:商场" + wiWideInfo.getTenantId()); | |||
| } | |||
| } | |||
| private void updateSercret(WxWiWideInfo wiWideInfo,WiwideSercret sercret) { | |||
| WxWiWideInfo record = new WxWiWideInfo(); | |||
| record.setId(wiWideInfo.getId()); | |||
| record.setWiwideId(sercret.getSecretId()); | |||
| record.setWiwideKey(sercret.getSecretKey()); | |||
| try { | |||
| logger.info("要更新的数据before>>>>>>>>>>"+JSONObject.toJSONString(record)); | |||
| wxWiwideInfoMapper.updateSercret(record); | |||
| logger.info("要更新的数据after>>>>>>>>>>"+JSONObject.toJSONString(record)); | |||
| } catch (MallinkException e) { | |||
| logger.info("更新TOKEN失败:商场" + wiWideInfo.getTenantId()); | |||
| } | |||
| } | |||
| /** | |||
| * 测试: http://140.143.33.245/ fm_test/Wiwide123 | |||
| @@ -820,6 +852,16 @@ public class DataTowerServiceImpl implements DataTowerService { | |||
| logger.info("返回的token:"+token); | |||
| return token; | |||
| } | |||
| private WiwideSercret getWiwideSercret(WxWiWideInfo wiWideInfo) { | |||
| if((!StringUtils.isBlank(wiWideInfo.getWiwideId())) && (!StringUtils.isBlank(wiWideInfo.getWiwideKey()))) { | |||
| return new WiwideSercret(wiWideInfo.getWiwideId(), wiWideInfo.getWiwideKey()); | |||
| }else { | |||
| WiwideSercret data = WiwideUtil.querySercret(wiWideInfo); | |||
| updateSercret(wiWideInfo, data); | |||
| return data; | |||
| } | |||
| } | |||
| @Override | |||
| public ResultData queryCustomerData(TenantEntity tenantEntity, Map<String, String> params) { | |||
| @@ -3,11 +3,19 @@ package com.iformall.sms.wiwide; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.io.UnsupportedEncodingException; | |||
| import java.security.Key; | |||
| import java.util.Calendar; | |||
| import javax.crypto.Cipher; | |||
| import javax.crypto.spec.SecretKeySpec; | |||
| import com.iformall.common.ErrorCode; | |||
| import com.iformall.domain.po.WxWiWideInfo; | |||
| import com.iformall.exception.MallinkException; | |||
| import com.iformall.utils.Base64Util; | |||
| import lombok.extern.slf4j.Slf4j; | |||
| @Slf4j | |||
| public class WiwideEntry { | |||
| private static final String AESTYPE = "AES/ECB/NoPadding"; | |||
| @@ -22,9 +30,9 @@ public class WiwideEntry { | |||
| * @return string(encrypt data) | |||
| * @throws UnsupportedEncodingException | |||
| */ | |||
| public static String encrypt(String keyStr, String plainText) throws UnsupportedEncodingException { | |||
| public static String encrypt(String keyStr, String plainText) throws Exception { | |||
| if(keyStr.length()!=32){ | |||
| return "invalid key"; | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "invalid signKey"); | |||
| } | |||
| byte[] encrypt = null; | |||
| byte[] bytes = plainText.getBytes(); // | |||
| @@ -73,7 +81,7 @@ public class WiwideEntry { | |||
| */ | |||
| public static String decrypt(String keyStr, String encryptData) throws UnsupportedEncodingException { | |||
| if(keyStr.length()!=32){ | |||
| return "invalid key"; | |||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(), "invalid signKey"); | |||
| } | |||
| byte[] decrypt = null; | |||
| try{ | |||
| @@ -128,7 +136,7 @@ public class WiwideEntry { | |||
| } | |||
| public static void main(String[] args) throws UnsupportedEncodingException{ | |||
| public static void main(String[] args) throws Exception{ | |||
| /** | |||
| * Signature签名生成规则为:SecretId+&_&+SecretKey+&_&+秒级时间戳【默认过期时间为5分钟】 | |||
| * Signature参数为每个接口请求必传参数【获取开发者id与令牌接口可不传】,放入Cookie中 | |||
| @@ -144,6 +152,22 @@ public class WiwideEntry { | |||
| System.out.print("decrypt data:"); | |||
| System.out.println(decString); | |||
| } | |||
| public static String encrypt(String signKey,String secretId,String secretKey,long seconds) { | |||
| String plainText = secretId+"&_&"+secretKey+"&_&"+String.valueOf(seconds);// | |||
| try { | |||
| return encrypt(signKey,plainText); | |||
| } catch (Exception e) { | |||
| log.error("wiwide encrypt error.",e); | |||
| return e.getMessage(); | |||
| } | |||
| } | |||
| public static String encrypt(WxWiWideInfo wiWideInfo) { | |||
| Calendar calendar=Calendar.getInstance(); | |||
| int seconds=calendar.get(Calendar.SECOND); | |||
| return encrypt(wiWideInfo.getSignKey(), wiWideInfo.getWiwideId(), wiWideInfo.getWiwideKey(), seconds); | |||
| } | |||
| } | |||
| @@ -2,15 +2,15 @@ package com.iformall.sms.wiwide; | |||
| import java.io.Serializable; | |||
| public class WiwideToken implements Serializable{ | |||
| public class WiwideSercret implements Serializable{ | |||
| private static final long serialVersionUID = -5462040922824432499L; | |||
| public WiwideToken() { | |||
| public WiwideSercret() { | |||
| } | |||
| public WiwideToken(String secretId,String secretKey) { | |||
| public WiwideSercret(String secretId,String secretKey) { | |||
| this.secretId = secretId; | |||
| this.secretKey = secretKey; | |||
| } | |||
| @@ -173,6 +173,41 @@ public class WiwideUtil implements SMSExcutor { | |||
| logger.info("商场:" + wiWideInfo.getTenantId() + ",返回TOKEN" + token); | |||
| return token; | |||
| } | |||
| public static WiwideSercret querySercret(WxWiWideInfo wiWideInfo) { | |||
| logger.info("获取WiwideSercret"); | |||
| String username = wiWideInfo.getWiwideId(); | |||
| String password = wiWideInfo.getPassword(); | |||
| if(StringUtils.isEmpty(username)){ | |||
| logger.error("商场:" + wiWideInfo.getTenantId() + ",wiwide info : wiwideId为空" ); | |||
| return null; | |||
| } | |||
| if(StringUtils.isEmpty(password)){ | |||
| logger.error("商场:" + wiWideInfo.getTenantId() + ",wiwide info : password为空" ); | |||
| return null; | |||
| } | |||
| Map<String, String> params = new HashMap<>(2); | |||
| params.put("username", username); | |||
| params.put("password", password); | |||
| String wiwideUrl = wiWideInfo.getWiwideUrl(); | |||
| String token = HttpUtil.doPost(wiwideUrl + "/api/user/auth", params); | |||
| logger.info("商场:" + wiWideInfo.getTenantId() + ",wiwide 返回sercret" + token); | |||
| JSONObject result = JSONObject.parseObject(token); | |||
| if (null != result ) { | |||
| String msg = result.getString("msg"); | |||
| JSONObject data = result.getJSONObject("data"); | |||
| if(null != data) { | |||
| String secretKey = data.getString("SecretKey"); | |||
| String secretId = data.getString("SecretId"); | |||
| return new WiwideSercret(secretId, secretKey); | |||
| }else { | |||
| throw new MallinkException(ErrorCode.SYS_SERVER_ERROR.getCode(),"wiwide getSercret error."+msg); | |||
| } | |||
| } | |||
| return null; | |||
| } | |||
| public static String queryData(WxWiWideInfo wiWideInfo, String token, Map<String, String> params) { | |||
| @@ -7,16 +7,18 @@ | |||
| <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" /> | |||
| <result column="wiwide_id" jdbcType="VARCHAR" property="wiwideId"/> | |||
| <result column="wiwide_key" jdbcType="VARCHAR" property="wiwideKey"/> | |||
| <result column="sign_key" jdbcType="VARCHAR" property="signKey"/> | |||
| <result column="wiwide_url" jdbcType="VARCHAR" property="wiwideUrl"/> | |||
| <result column="token" jdbcType="VARCHAR" property="token"/> | |||
| <result column="expired_time" jdbcType="TIMESTAMP" property="expiredTime"/> | |||
| <result column="capability" jdbcType="VARCHAR" property="capability"/> | |||
| <result column="user_name" jdbcType="VARCHAR" property="userName"/> | |||
| <result column="password" jdbcType="VARCHAR" property="password"/> | |||
| <result column="old_plat" jdbcType="VARCHAR" property="oldPlat"/> | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`parent_tenant_id`,`wiwide_id`,`wiwide_key`,`wiwide_url`, `token`,`expired_time`,`capability`,`user_name`,`password` | |||
| `id`,`tenant_id`,`parent_tenant_id`,`wiwide_id`,`wiwide_key`,`sign_key`,`wiwide_url`, `token`,`expired_time`,`capability`,`user_name`,`password`,`old_plat` | |||
| </sql> | |||
| <sql id="dynamicWhereConditions"> | |||
| @@ -36,6 +38,11 @@ | |||
| <if test=" null != wiwideId "> | |||
| and `wiwide_id` like concat('%', #{wiwideId},'%') | |||
| </if> | |||
| <if test=" null != oldPlat "> | |||
| and `old_plat` = #{oldPlat} | |||
| </if> | |||
| <if test=" null != ids "> | |||
| and id in | |||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||
| @@ -55,6 +62,10 @@ | |||
| <update id="updateToken" parameterType="com.iformall.domain.po.WxWiWideInfo"> | |||
| update wx_wiwide_info set token=#{token},expired_time=#{expiredTime} where id=#{id} | |||
| </update> | |||
| <update id="updateSercret" parameterType="com.iformall.domain.po.WxWiWideInfo"> | |||
| update wx_wiwide_info set wiwide_id=#{wiwideId},wiwide_key=#{wiwideKey} where id=#{id} | |||
| </update> | |||
| </mapper> | |||