| @@ -87,7 +87,7 @@ public class DataTowerController extends BaseController { | |||
| public ResultData queryCustomerNewVersion() { | |||
| logger.debug("[" + getIpAddr() + "] DataTowerController::queryCustomerNewVersion"); | |||
| Map<String, Object> data = dataTowerService.queryCustomer(getTenantInfo()); | |||
| Map<String, Object> data = dataTowerService.queryCustomerNewVersion(getTenantInfo()); | |||
| return new ResultData(data); | |||
| } | |||
| @@ -39,3 +39,5 @@ 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`; | |||
| @@ -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; | |||
| @@ -40,5 +43,5 @@ public class WxWiWideInfo extends TenantEntity { | |||
| @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); | |||
| } | |||
| @@ -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; | |||
| @@ -792,7 +793,8 @@ public class DataTowerServiceImpl implements DataTowerService { | |||
| if(list.size()>0){ | |||
| wiWideInfo = list.get(0); | |||
| String wiwideUrl = wiWideInfo.getWiwideUrl(); | |||
| datamap.put("token", getWiwideToken(wiWideInfo)); | |||
| datamap.put("token", getWiwideSercret(wiWideInfo)); | |||
| datamap.put("sign", WiwideEntry.encrypt(wiWideInfo)); | |||
| datamap.put("url", wiwideUrl); | |||
| datamap.put("capability", wiWideInfo.getCapability()); | |||
| } | |||
| @@ -815,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 | |||
| @@ -836,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,6 +7,7 @@ | |||
| <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"/> | |||
| @@ -17,7 +18,7 @@ | |||
| </resultMap> | |||
| <sql id="allColumns"> | |||
| `id`,`tenant_id`,`parent_tenant_id`,`wiwide_id`,`wiwide_key`,`wiwide_url`, `token`,`expired_time`,`capability`,`user_name`,`password`,`old_plat` | |||
| `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"> | |||
| @@ -61,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> | |||