| @@ -0,0 +1,41 @@ | |||||
| package com.iformall.controller.rent; | |||||
| import com.iformall.annotation.SystemControllerLog; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.controller.base.BaseController; | |||||
| import com.iformall.service.WxGooagooService; | |||||
| 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("gooagoo") | |||||
| public class WxGooagooController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | |||||
| WxGooagooService wxGooagooService; | |||||
| @ApiOperation("调取接口数据") | |||||
| @PostMapping("/queryData") | |||||
| @SystemControllerLog(description = "数据塔台-查询客流") | |||||
| public ResultData queryData(@RequestBody Map<String,Object> params) { | |||||
| logger.debug("[" + getIpAddr() + "] WxGooagooController::queryData"); | |||||
| Object lowerMethod = params.get("lowerMethod"); | |||||
| if(lowerMethod == null){ | |||||
| return new ResultData(ErrorCode.SYS_PARAMETER_NOT_NULL,"lowerMethod不能为空"); | |||||
| } | |||||
| String requrl = lowerMethod.toString(); | |||||
| params.remove("lowerMethod"); | |||||
| return wxGooagooService.queryDataUrl(getTenantInfo(),requrl,params); | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,16 @@ | |||||
| CREATE TABLE `wx_third_party_config` ( | |||||
| `id` bigint(20) NOT NULL COMMENT '主键ID', | |||||
| `tenant_id` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL COMMENT '租户ID', | |||||
| `parent_tenant_id` varchar(5) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '父租户ID', | |||||
| `type` tinyint(6) NOT NULL COMMENT '第三方类型,', | |||||
| `app_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL, | |||||
| `app_key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL, | |||||
| `sign_key` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '加密key,', | |||||
| `api_url` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL, | |||||
| `token` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL, | |||||
| `token_expired_time` datetime(0) DEFAULT NULL COMMENT 'token过期时间', | |||||
| `user_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '登陆账号', | |||||
| `password` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL COMMENT '登陆密码', | |||||
| `version` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT '' COMMENT '接口版本', | |||||
| PRIMARY KEY (`id`) USING BTREE | |||||
| ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; | |||||
| @@ -598,6 +598,12 @@ public enum ErrorCode{ | |||||
| QUESTION_USER_NOT(61006, "答题参数错误!"), | QUESTION_USER_NOT(61006, "答题参数错误!"), | ||||
| QUESTION_USER_LINE(61007, "已经参与!"), | QUESTION_USER_LINE(61007, "已经参与!"), | ||||
| /** | |||||
| * 数衍信息 | |||||
| */ | |||||
| GOOAGOO_INFO_NOT_FOUND(62001,"数衍信息未找到"), | |||||
| GOOAGOO_OPEN_FAIL(62002,"数衍信息请求失败"), | |||||
| ; | ; | ||||
| @@ -0,0 +1,47 @@ | |||||
| package com.iformall.domain.po; | |||||
| import com.baomidou.mybatisplus.annotation.TableName; | |||||
| import com.iformall.domain.po.base.TenantEntity; | |||||
| import lombok.Data; | |||||
| import lombok.EqualsAndHashCode; | |||||
| import java.util.Date; | |||||
| @TableName(value = "wx_third_party_config") | |||||
| @Data | |||||
| @EqualsAndHashCode(callSuper = true) | |||||
| public class WxThirdPartyConfig extends TenantEntity { | |||||
| protected Long id; | |||||
| @io.swagger.annotations.ApiModelProperty(value="",name="type") | |||||
| private Integer type; | |||||
| @io.swagger.annotations.ApiModelProperty(value="",name="appId") | |||||
| private String appId; | |||||
| @io.swagger.annotations.ApiModelProperty(value="",name="appKey") | |||||
| private String appKey; | |||||
| @io.swagger.annotations.ApiModelProperty(value="加密key",name="signKey") | |||||
| private String signKey; | |||||
| @io.swagger.annotations.ApiModelProperty(value="",name="apiUrl") | |||||
| private String apiUrl; | |||||
| @io.swagger.annotations.ApiModelProperty(value="token",name="token") | |||||
| private String token; | |||||
| @io.swagger.annotations.ApiModelProperty(value="",name="tokenExpiredTime") | |||||
| private Date tokenExpiredTime; | |||||
| @io.swagger.annotations.ApiModelProperty(value="登陆username",name="userName") | |||||
| private String userName; | |||||
| @io.swagger.annotations.ApiModelProperty(value="登陆password",name="password") | |||||
| private String password; | |||||
| @io.swagger.annotations.ApiModelProperty(value="",name="version") | |||||
| private String version; | |||||
| } | |||||
| @@ -0,0 +1,36 @@ | |||||
| package com.iformall.enums; | |||||
| /** | |||||
| * @author gongbiao | |||||
| */ | |||||
| public enum EnumThirdPartyConfigType { | |||||
| GOOAGOO(5, "数衍科技"), | |||||
| ; | |||||
| public static EnumThirdPartyConfigType getEnum(Integer code) { | |||||
| for (EnumThirdPartyConfigType value : values()) { | |||||
| if (value.getCode().equals(code)) { | |||||
| return value; | |||||
| } | |||||
| } | |||||
| return null; | |||||
| } | |||||
| private Integer code; | |||||
| private String message; | |||||
| EnumThirdPartyConfigType(Integer code, String message) { | |||||
| this.code = code; | |||||
| this.message = message; | |||||
| } | |||||
| public Integer getCode() { | |||||
| return code; | |||||
| } | |||||
| public String getMessage() { | |||||
| return message; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,12 @@ | |||||
| package com.iformall.mapper; | |||||
| import com.iformall.common.CommonMapper; | |||||
| import com.iformall.domain.po.WxThirdPartyConfig; | |||||
| import java.util.List; | |||||
| public interface WxThirdPartyConfigMapper extends CommonMapper<WxThirdPartyConfig, Long> { | |||||
| List<WxThirdPartyConfig> findList(WxThirdPartyConfig config); | |||||
| } | |||||
| @@ -0,0 +1,12 @@ | |||||
| package com.iformall.service; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.base.TenantEntity; | |||||
| import java.util.Map; | |||||
| public interface WxGooagooService { | |||||
| ResultData queryDataUrl(TenantEntity tenantInfo, String url, Map<String, Object> params); | |||||
| } | |||||
| @@ -0,0 +1,92 @@ | |||||
| package com.iformall.service.impl; | |||||
| import com.alibaba.druid.support.json.JSONUtils; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||||
| import com.iformall.common.ErrorCode; | |||||
| import com.iformall.common.Result; | |||||
| import com.iformall.common.ResultData; | |||||
| import com.iformall.domain.po.WxThirdPartyConfig; | |||||
| import com.iformall.domain.po.base.TenantEntity; | |||||
| import com.iformall.enums.EnumThirdPartyConfigType; | |||||
| import com.iformall.mapper.WxThirdPartyConfigMapper; | |||||
| import com.iformall.service.*; | |||||
| import com.iformall.utils.DateUtils; | |||||
| import com.iformall.utils.HttpUtil; | |||||
| import com.iformall.utils.gooagoo.SignUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.*; | |||||
| /** | |||||
| */ | |||||
| @Service | |||||
| public class WxGooagooServiceImpl implements WxGooagooService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| private final String method = "gogo.open.auto.routing"; | |||||
| private final String v = "1.0"; | |||||
| @Autowired | |||||
| WxThirdPartyConfigMapper wxThirdPartyConfigMapper; | |||||
| /** | |||||
| * @param tenantEntity | |||||
| * @param url | |||||
| * @param params | |||||
| * @return | |||||
| */ | |||||
| @Override | |||||
| public ResultData queryDataUrl(TenantEntity tenantEntity, String url, Map<String, Object> params) { | |||||
| WxThirdPartyConfig configQ = new WxThirdPartyConfig(); | |||||
| configQ.updateTenantInfo(tenantEntity); | |||||
| configQ.setType(EnumThirdPartyConfigType.GOOAGOO.getCode()); | |||||
| configQ.setVersion(v); | |||||
| WxThirdPartyConfig config = wxThirdPartyConfigMapper.selectOne(new QueryWrapper<>(configQ)); | |||||
| if(config == null){ | |||||
| return new ResultData(ErrorCode.GOOAGOO_INFO_NOT_FOUND); | |||||
| } | |||||
| Map<String,String> paramMap = this.getParamMap(config); | |||||
| paramMap.put("lowerMethod",url); | |||||
| paramMap.put("data", JSONUtils.toJSONString(params)); | |||||
| String sign= SignUtils.sign(config.getSignKey(),paramMap); | |||||
| paramMap.put("sign",sign); | |||||
| String res = HttpUtil.doPost(config.getApiUrl(), paramMap); | |||||
| JSONObject result = JSONObject.parseObject(res); | |||||
| if (result == null) | |||||
| return new ResultData(ErrorCode.GOOAGOO_INFO_NOT_FOUND); | |||||
| if ("OPEN_SUCCESS".equals(result.getString("rescode"))){ | |||||
| return new ResultData(Result.SUCCESS,result.getString("resmsg"), | |||||
| result.getJSONObject("data")); | |||||
| } else{ | |||||
| return new ResultData(ErrorCode.GOOAGOO_OPEN_FAIL,result.getString("resmsg")); | |||||
| } | |||||
| } | |||||
| private Map<String,String> getParamMap(WxThirdPartyConfig config){ | |||||
| Map<String,String> map = new HashMap<>(); | |||||
| map.put("appId",config.getAppId()); | |||||
| map.put("appKey",config.getAppKey()); | |||||
| map.put("method",method); | |||||
| map.put("timestamp", DateUtils.getSystemTime("yyyyMMDDHHmmss")); | |||||
| map.put("messageFormat","json"); | |||||
| map.put("v",v); | |||||
| map.put("sign",config.getSignKey()); | |||||
| map.put("signMethod","MD5"); | |||||
| return map; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,78 @@ | |||||
| package com.iformall.utils.gooagoo; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import java.security.MessageDigest; | |||||
| import java.util.Arrays; | |||||
| import java.util.Map; | |||||
| public class SignUtils { | |||||
| private final static Logger logger = LoggerFactory.getLogger(SignUtils.class); | |||||
| public SignUtils() { | |||||
| } | |||||
| public static String sign(String appSecret, Map<String, String> form) { | |||||
| return getSign(appSecret, form, (String)form.get("signMethod")); | |||||
| } | |||||
| public static String getSign(String appSecret, Map<String, String> params, String signMethod) { | |||||
| String[] keys = (String[])params.keySet().toArray(new String[0]); | |||||
| Arrays.sort(keys); | |||||
| StringBuilder signStr = new StringBuilder(); | |||||
| String[] var5 = keys; | |||||
| int var6 = keys.length; | |||||
| for(int var7 = 0; var7 < var6; ++var7) { | |||||
| String key = var5[var7]; | |||||
| String value = (String)params.get(key); | |||||
| if (value != null && !"".equals(value)) { | |||||
| signStr.append(key).append("=").append(value).append("&"); | |||||
| } | |||||
| } | |||||
| signStr.append("key=").append(appSecret); | |||||
| logger.info("服务端的签名之前的字符串:" + signStr.toString()); | |||||
| if ("MD5".equals(signMethod)) { | |||||
| return getMD5(signStr.toString()); | |||||
| } else { | |||||
| return getSHA(signStr.toString()); | |||||
| } | |||||
| } | |||||
| public static String getSHA(String str) { | |||||
| return encrypt(str, "SHA"); | |||||
| } | |||||
| public static String getMD5(String str) { | |||||
| return encrypt(str, "MD5"); | |||||
| } | |||||
| private static String encrypt(String str, String algorithm) { | |||||
| try { | |||||
| MessageDigest md = MessageDigest.getInstance(algorithm); | |||||
| md.update(str.getBytes("UTF-8")); | |||||
| byte[] digest = md.digest(); | |||||
| StringBuffer hexstr = new StringBuffer(); | |||||
| String shaHex = ""; | |||||
| for(int i = 0; i < digest.length; ++i) { | |||||
| shaHex = Integer.toHexString(digest[i] & 255); | |||||
| if (shaHex.length() < 2) { | |||||
| hexstr.append(0); | |||||
| } | |||||
| hexstr.append(shaHex); | |||||
| } | |||||
| return hexstr.toString().toUpperCase(); | |||||
| } catch (Exception var7) { | |||||
| var7.printStackTrace(); | |||||
| // throw new Exception(var7); | |||||
| } | |||||
| return null; | |||||
| } | |||||
| } | |||||
| @@ -0,0 +1,71 @@ | |||||
| <?xml version="1.0" encoding="UTF-8"?> | |||||
| <!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |||||
| <mapper namespace="com.iformall.mapper.WxThirdPartyConfigMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxThirdPartyConfig"> | |||||
| <id column="id" jdbcType="BIGINT" property="id"/> | |||||
| <result column="tenant_id" jdbcType="VARCHAR" property="tenantId"/> | |||||
| <result column="parent_tenant_id" jdbcType="VARCHAR" property="parentTenantId" /> | |||||
| <result column="type" jdbcType="INTEGER" property="type"/> | |||||
| <result column="app_id" jdbcType="VARCHAR" property="appId"/> | |||||
| <result column="app_key" jdbcType="VARCHAR" property="appKey"/> | |||||
| <result column="sign_key" jdbcType="VARCHAR" property="signKey"/> | |||||
| <result column="api_url" jdbcType="VARCHAR" property="apiUrl"/> | |||||
| <result column="token" jdbcType="VARCHAR" property="token"/> | |||||
| <result column="token_expired_time" jdbcType="TIMESTAMP" property="tokenExpiredTime"/> | |||||
| <result column="user_name" jdbcType="VARCHAR" property="userName"/> | |||||
| <result column="password" jdbcType="VARCHAR" property="password"/> | |||||
| <result column="version" jdbcType="VARCHAR" property="version"/> | |||||
| </resultMap> | |||||
| <sql id="allColumns"> | |||||
| `id`,`tenant_id`,`parent_tenant_id`,`type`,`app_id`,`app_key`,`sign_key`,`api_url`, `token`,`token_expired_time`,`user_name`,`password`,`version` | |||||
| </sql> | |||||
| <sql id="dynamicWhereConditions"> | |||||
| where 1 = 1 | |||||
| <if test=" null != id "> | |||||
| and `id` = #{id} | |||||
| </if> | |||||
| <if test=" null != tenantId and '' != tenantId"> | |||||
| and `tenant_id` = #{tenantId} | |||||
| </if> | |||||
| <if test=" null != parentTenantId and '' != parentTenantId"> | |||||
| and `parent_tenant_id` = #{parentTenantId} | |||||
| </if> | |||||
| <if test=" null != type "> | |||||
| and `type` = #{type} | |||||
| </if> | |||||
| <if test=" null != version and '' != version"> | |||||
| and `version` = #{version} | |||||
| </if> | |||||
| <if test=" null != ids "> | |||||
| and id in | |||||
| <foreach collection="ids" index="index" item="idItem" open="(" separator="," close=")"> | |||||
| #{idItem} | |||||
| </foreach> | |||||
| </if> | |||||
| <if test=" null != sortColumns">order by ${sortColumns}</if> | |||||
| </sql> | |||||
| <select id="findList" parameterType="com.iformall.domain.po.WxThirdPartyConfig" resultMap="BaseResultMap"> | |||||
| select | |||||
| <include refid="allColumns"/> | |||||
| from wx_third_party_config | |||||
| <include refid="dynamicWhereConditions"/> | |||||
| </select> | |||||
| <update id="updateToken" parameterType="com.iformall.domain.po.WxThirdPartyConfig"> | |||||
| update wx_third_party_config set token=#{token},token_expired_time=#{tokenExpiredTime} where id=#{id} | |||||
| </update> | |||||
| <update id="updateSercret" parameterType="com.iformall.domain.po.WxThirdPartyConfig"> | |||||
| update wx_third_party_config set app_id=#{appId},app_key=#{appKey} where id=#{id} | |||||
| </update> | |||||
| </mapper> | |||||