| @@ -0,0 +1,18 @@ | |||||
| CREATE TABLE `wx_third_party_api` ( | |||||
| `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 DEFAULT 1 COMMENT '第三方类型,', | |||||
| `app_id` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, | |||||
| `app_key` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL, | |||||
| `sign_key` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT 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 DEFAULT '' COMMENT '接口版本', | |||||
| `tp_id` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci DEFAULT NULL, | |||||
| PRIMARY KEY (`id`) USING BTREE, | |||||
| UNIQUE INDEX `app_id`(`app_id`) USING BTREE | |||||
| ) ENGINE = InnoDB CHARACTER SET = utf8mb4 COLLATE = utf8mb4_unicode_ci ROW_FORMAT = Dynamic; | |||||
| @@ -0,0 +1,36 @@ | |||||
| package com.iformall.controller; | |||||
| import com.iformall.common.ResultData; | |||||
| import io.swagger.annotations.Api; | |||||
| import io.swagger.annotations.ApiOperation; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.web.bind.annotation.*; | |||||
| import java.util.Map; | |||||
| @RestController | |||||
| @RequestMapping("/api/userInfo") | |||||
| @Api(description = "会员相关接口") | |||||
| public class UserBasicInfoController extends BaseController { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| /** | |||||
| * 用户注册 | |||||
| * | |||||
| * @param map | |||||
| * @return | |||||
| */ | |||||
| @PostMapping("/register") | |||||
| @ApiOperation(value = "用户注册", notes = "") | |||||
| public ResultData userRegister(@RequestParam Map<String, String> map) { | |||||
| logger.info("UserBasicInfoController >>>>>>>> userRegister >>>>>>>>>>>>>>>>>"+map.toString()); | |||||
| String phone = map.get("phone"); | |||||
| logger.info("UserBasicInfoController >>>>>>>> userRegister >>>>>>>>>>>>>>>>>phone="+phone); | |||||
| return new ResultData(); | |||||
| } | |||||
| } | |||||
| @@ -2,11 +2,16 @@ package com.iformall.interceptor; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.domain.po.WxThirdPartyApi; | |||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.utils.HashUtil; | |||||
| import com.iformall.service.WxThirdPartyApiService; | |||||
| import com.iformall.utils.Constant; | |||||
| import com.iformall.utils.RedisCacheUtils; | import com.iformall.utils.RedisCacheUtils; | ||||
| import com.iformall.utils.sign.SignUtils; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.beans.factory.annotation.Qualifier; | import org.springframework.beans.factory.annotation.Qualifier; | ||||
| import org.springframework.data.redis.core.RedisTemplate; | import org.springframework.data.redis.core.RedisTemplate; | ||||
| @@ -15,6 +20,7 @@ import org.springframework.web.servlet.handler.HandlerInterceptorAdapter; | |||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||
| import java.util.*; | |||||
| /** | /** | ||||
| * 权限(Token)验证 | * 权限(Token)验证 | ||||
| @@ -25,44 +31,80 @@ import javax.servlet.http.HttpServletResponse; | |||||
| @Component | @Component | ||||
| public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | public class AuthorizationInterceptor extends HandlerInterceptorAdapter { | ||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| @Autowired | @Autowired | ||||
| @Qualifier("objectCommonRedisTemplate") | @Qualifier("objectCommonRedisTemplate") | ||||
| RedisTemplate<String, Object> redisTemplate; | RedisTemplate<String, Object> redisTemplate; | ||||
| @Autowired | |||||
| WxThirdPartyApiService wxThirdPartyApiService; | |||||
| @Override | @Override | ||||
| public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception { | ||||
| String cid = request.getParameter("cId");//调用方ID | |||||
| String nonceStr = request.getParameter("nonceStr");//随机字符串 | |||||
| String signKey = request.getParameter("signKey");//随机字符串 | |||||
| if(StringUtils.isBlank(cid) || "null".equals(cid) || "undefined".equals(cid)){ | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"cId为空["+cid+"]"); | |||||
| String cookie = request.getHeader("cookie"); | |||||
| if (StringUtils.isBlank(cookie) || !cookie.contains("&")) { | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"非法请求"); | |||||
| } | |||||
| String[] split = cookie.split("&"); | |||||
| WxThirdPartyApi apiConfig = wxThirdPartyApiService.findByApp(split[0], split[1]); | |||||
| if(apiConfig == null){ | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"非法请求"); | |||||
| } | } | ||||
| if(StringUtils.isBlank(nonceStr) || "null".equals(nonceStr) || "undefined".equals(nonceStr)){ | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"nonceStr为空["+nonceStr+"]"); | |||||
| String signature = request.getHeader("sign"); | |||||
| logger.info("sign={}"+signature); | |||||
| //没有加密 | |||||
| if (StringUtils.isBlank(signature)) { | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"缺少加密串"); | |||||
| } | } | ||||
| if(StringUtils.isBlank(signKey) || "null".equals(signKey) || "undefined".equals(signKey)){ | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"signKey为空["+signKey+"]"); | |||||
| String timeStamp = request.getParameter("timeStamp"); | |||||
| long timestampDate = Long.valueOf(timeStamp) + 1000*60*5;//五分钟有效 | |||||
| long currDate = System.currentTimeMillis(); | |||||
| // 请求过期 | |||||
| if (timestampDate < currDate) { | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"请求过期"); | |||||
| } | } | ||||
| //nonceStr必须唯一,为防止接口盗刷,每次只能调用一次 | |||||
| Integer cache = RedisCacheUtils.getCacheInteger(redisTemplate, "publicApi:"+nonceStr); | |||||
| String nonceStr = request.getParameter("nonceStr"); | |||||
| //重复调用 | |||||
| Integer cache = RedisCacheUtils.getCacheInteger(redisTemplate, Constant.publicApiNonce+nonceStr); | |||||
| if (null != cache) { | if (null != cache) { | ||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"不能重复调用"); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"重复调用"); | |||||
| } | |||||
| Enumeration<String> paramNames = request.getParameterNames(); | |||||
| Map map = new HashMap(); | |||||
| //获取所有的请求参数 | |||||
| while (paramNames.hasMoreElements()) { | |||||
| String paramName = paramNames.nextElement(); | |||||
| String[] paramValues = request.getParameterValues(paramName); | |||||
| if (paramValues.length > 0) { | |||||
| String paramValue = paramValues[0]; | |||||
| if (paramValue.length() != 0 | |||||
| && !"sign".equals(paramName) | |||||
| && !"appId".equals(paramName) | |||||
| && !"appKey".equals(paramName) | |||||
| && !"signKey".equals(paramName)) { | |||||
| map.put(paramName, paramValue); | |||||
| } | |||||
| } | |||||
| } | } | ||||
| //TODO singnKey是根据cid+cid对应的密钥+nonceStr | |||||
| String secretKey = "";//TODO 根据cid查询密钥,缓存 | |||||
| String signstr = HashUtil.md5(cid+secretKey+nonceStr); | |||||
| if (!signKey.equals(signstr)) { | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"加密串校验失败"); | |||||
| logger.info("sign={}"+signature); | |||||
| String signKey = apiConfig.getSignKey();//TODO 根据appId查询密钥,缓存 | |||||
| String newSignature = SignUtils.getSign(signKey, map, "MD5"); | |||||
| //加密串不匹配 | |||||
| if (!signature.equals(newSignature)) { | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR.getCode(),"加密串校验失败"); | |||||
| } | } | ||||
| RedisCacheUtils.cache(redisTemplate, "publicApi:"+nonceStr, 1, 600); | |||||
| RedisCacheUtils.cache(redisTemplate, Constant.publicApiNonce+nonceStr, 1, 300); | |||||
| return true; | return true; | ||||
| } | } | ||||
| } | } | ||||
| @@ -599,6 +599,7 @@ public enum ErrorCode{ | |||||
| QUESTION_USER_LINE(61007, "已经参与!"), | QUESTION_USER_LINE(61007, "已经参与!"), | ||||
| QUESTION_NOT_START(61008, "问卷未开始"), | QUESTION_NOT_START(61008, "问卷未开始"), | ||||
| QUESTION_END(61009, "问卷已结束"), | QUESTION_END(61009, "问卷已结束"), | ||||
| QUESTION_END_LINE(61010, "问卷已下线"), | |||||
| /** | /** | ||||
| * 数衍信息 | * 数衍信息 | ||||
| @@ -0,0 +1,50 @@ | |||||
| 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_Api") | |||||
| @Data | |||||
| @EqualsAndHashCode(callSuper = true) | |||||
| public class WxThirdPartyApi 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; | |||||
| @io.swagger.annotations.ApiModelProperty(value="",name="tpId") | |||||
| private String tpId; | |||||
| } | |||||
| @@ -0,0 +1,12 @@ | |||||
| package com.iformall.mapper; | |||||
| import com.iformall.common.CommonMapper; | |||||
| import com.iformall.domain.po.WxThirdPartyApi; | |||||
| import java.util.List; | |||||
| public interface WxThirdPartyApiMapper extends CommonMapper<WxThirdPartyApi, Long> { | |||||
| List<WxThirdPartyApi> findList(WxThirdPartyApi apiConfig); | |||||
| } | |||||
| @@ -0,0 +1,21 @@ | |||||
| package com.iformall.service; | |||||
| import com.iformall.domain.po.WxThirdPartyApi; | |||||
| import java.util.List; | |||||
| /** | |||||
| * | |||||
| */ | |||||
| public interface WxThirdPartyApiService { | |||||
| /** | |||||
| * 查询列表 | |||||
| * | |||||
| * @param record | |||||
| */ | |||||
| List<WxThirdPartyApi> findList(WxThirdPartyApi record); | |||||
| WxThirdPartyApi findByApp(String appId, String appKey); | |||||
| } | |||||
| @@ -13,7 +13,7 @@ import com.iformall.mapper.WxThirdPartyConfigMapper; | |||||
| import com.iformall.service.*; | import com.iformall.service.*; | ||||
| import com.iformall.utils.DateUtils; | import com.iformall.utils.DateUtils; | ||||
| import com.iformall.utils.HttpUtil; | import com.iformall.utils.HttpUtil; | ||||
| import com.iformall.utils.gooagoo.SignUtils; | |||||
| import com.iformall.utils.sign.SignUtils; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| @@ -116,9 +116,14 @@ public class WxQuestionOneselfServiceImpl implements WxQuestionOneselfService { | |||||
| topic.setUpdateDate(now); | topic.setUpdateDate(now); | ||||
| topic.setSort(i+1); | topic.setSort(i+1); | ||||
| } | } | ||||
| wxQuestionOneselfTopicMapper.insertList(topicList); | |||||
| try{ | |||||
| wxQuestionOneselfTopicMapper.insertList(topicList); | |||||
| }catch (Exception e){ | |||||
| logger.error("添加答题问卷: {}" + e.getMessage()); | |||||
| throw new MallinkException(ErrorCode.SYS_PARAMETER_ERROR); | |||||
| } | |||||
| } | } | ||||
| if(record.getCountTopic() == null || record.getCountTopic().intValue() != countTopic){ | if(record.getCountTopic() == null || record.getCountTopic().intValue() != countTopic){ | ||||
| @@ -8,6 +8,7 @@ import com.github.pagehelper.PageInfo; | |||||
| import com.iformall.common.ErrorCode; | import com.iformall.common.ErrorCode; | ||||
| import com.iformall.common.IdWorker; | import com.iformall.common.IdWorker; | ||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.enums.EnumQuestionOneselfStatus; | |||||
| import com.iformall.enums.EnumScoreType; | import com.iformall.enums.EnumScoreType; | ||||
| import com.iformall.enums.EnumUserType; | import com.iformall.enums.EnumUserType; | ||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| @@ -138,12 +139,17 @@ public class WxQuestionOneselfUserServiceImpl implements WxQuestionOneselfUserSe | |||||
| } | } | ||||
| wxQuestionOneselfLogMapper.insertList(logList); | wxQuestionOneselfLogMapper.insertList(logList); | ||||
| }else{ | }else{ | ||||
| throw new MallinkException(ErrorCode.QUESTION_UPUP_LINE); | |||||
| throw new MallinkException(ErrorCode.QUESTION_USER_NOT); | |||||
| } | } | ||||
| wxQuestionOneselfMapper.updateCountUser(record.getQuestionId()); | wxQuestionOneselfMapper.updateCountUser(record.getQuestionId()); | ||||
| WxQuestionOneself wxQuestionOneself = wxQuestionOneselfMapper.selectById(record.getQuestionId()); | WxQuestionOneself wxQuestionOneself = wxQuestionOneselfMapper.selectById(record.getQuestionId()); | ||||
| if(!wxQuestionOneself.getStatus().equals(EnumQuestionOneselfStatus.INJECT_CAMPAIGN.getCode()) | |||||
| && !wxQuestionOneself.getStatus().equals(EnumQuestionOneselfStatus.INJECT_ONLINE.getCode())){ | |||||
| throw new MallinkException(ErrorCode.QUESTION_END_LINE); | |||||
| } | |||||
| if(now.before(wxQuestionOneself.getStartDate())){ | if(now.before(wxQuestionOneself.getStartDate())){ | ||||
| throw new MallinkException(ErrorCode.QUESTION_NOT_START); | throw new MallinkException(ErrorCode.QUESTION_NOT_START); | ||||
| } | } | ||||
| @@ -0,0 +1,54 @@ | |||||
| package com.iformall.service.impl; | |||||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||||
| import com.iformall.domain.po.WxAppinfo; | |||||
| import com.iformall.domain.po.WxThirdPartyApi; | |||||
| import com.iformall.mapper.WxThirdPartyApiMapper; | |||||
| import com.iformall.service.WxThirdPartyApiService; | |||||
| import com.iformall.utils.Constant; | |||||
| import com.iformall.utils.RedisCacheUtils; | |||||
| import org.apache.commons.lang3.StringUtils; | |||||
| import org.slf4j.Logger; | |||||
| import org.slf4j.LoggerFactory; | |||||
| import org.springframework.beans.factory.annotation.Autowired; | |||||
| import org.springframework.beans.factory.annotation.Qualifier; | |||||
| import org.springframework.data.redis.core.RedisTemplate; | |||||
| import org.springframework.stereotype.Service; | |||||
| import java.util.List; | |||||
| @Service | |||||
| public class WxThirdPartyApiServiceImpl implements WxThirdPartyApiService { | |||||
| private final Logger logger = LoggerFactory.getLogger(this.getClass()); | |||||
| WxThirdPartyApiMapper wxThirdPartyApiMapper; | |||||
| @Autowired | |||||
| @Qualifier("objectCommonRedisTemplate") | |||||
| RedisTemplate<String, Object> redisTemplate; | |||||
| @Override | |||||
| public List<WxThirdPartyApi> findList(WxThirdPartyApi record) { | |||||
| return wxThirdPartyApiMapper.findList(record); | |||||
| } | |||||
| @Override | |||||
| public WxThirdPartyApi findByApp(String appId, String appKey) { | |||||
| if(StringUtils.isBlank(appId) || StringUtils.isBlank(appKey)){ | |||||
| return null; | |||||
| } | |||||
| WxThirdPartyApi apiConfig = null; | |||||
| apiConfig = RedisCacheUtils.getCacheObject(redisTemplate, Constant.publicApi + appId, WxThirdPartyApi.class); | |||||
| if(apiConfig != null){ | |||||
| return apiConfig; | |||||
| } | |||||
| WxThirdPartyApi apiQ = new WxThirdPartyApi(); | |||||
| apiQ.setAppId(appId); | |||||
| apiQ.setAppKey(appKey); | |||||
| apiConfig = wxThirdPartyApiMapper.selectOne(new QueryWrapper<>(apiQ)); | |||||
| RedisCacheUtils.cache(redisTemplate, Constant.publicApi + appId, apiConfig,0l); | |||||
| return apiConfig; | |||||
| } | |||||
| } | |||||
| @@ -42,6 +42,9 @@ public class Constant { | |||||
| public static final String cuserQr = "weapp:cuser-qr:"; | public static final String cuserQr = "weapp:cuser-qr:"; | ||||
| public static final String publicApi = "publicApi:"; | |||||
| public static final String publicApiNonce = publicApi + "nonce:"; | |||||
| public static final String LOGIN_USER_KEY = "LOGIN_USER_KEY"; | public static final String LOGIN_USER_KEY = "LOGIN_USER_KEY"; | ||||
| public static final String LOGIN_MEMBER_KEY = "LOGIN_MEMBER_KEY"; | public static final String LOGIN_MEMBER_KEY = "LOGIN_MEMBER_KEY"; | ||||
| public static final String TENANT_ID = "TENANT_ID"; | public static final String TENANT_ID = "TENANT_ID"; | ||||
| @@ -0,0 +1,122 @@ | |||||
| package com.iformall.utils.sign; | |||||
| import java.security.MessageDigest; | |||||
| import java.security.NoSuchAlgorithmException; | |||||
| import java.util.Arrays; | |||||
| import java.util.Date; | |||||
| import java.util.UUID; | |||||
| /** | |||||
| * @Title: AppUtils | |||||
| * @Description: 随机产生唯一的app_key和app_secret | |||||
| */ | |||||
| public class AppUtils { | |||||
| //生成 app_secret 密钥 | |||||
| private final static String SERVER_NAME = "formall"; | |||||
| private final static String[] chars = new String[]{"a", "b", "c", "d", "e", "f", | |||||
| "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s", | |||||
| "t", "u", "v", "w", "x", "y", "z", "0", "1", "2", "3", "4", "5", | |||||
| "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H", "I", | |||||
| "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", | |||||
| "W", "X", "Y", "Z"}; | |||||
| /** | |||||
| * @Description: <p> | |||||
| * 短8位UUID思想其实借鉴微博短域名的生成方式,但是其重复概率过高,而且每次生成4个,需要随即选取一个。 | |||||
| * 本算法利用62个可打印字符,通过随机生成32位UUID,由于UUID都为十六进制,所以将UUID分成8组,每4个为一组,然后通过模62操作,结果作为索引取出字符, | |||||
| * 这样重复率大大降低。 | |||||
| * 经测试,在生成一千万个数据也没有出现重复,完全满足大部分需求。 | |||||
| * </p> | |||||
| */ | |||||
| public static String getAppId() { | |||||
| StringBuffer shortBuffer = new StringBuffer(); | |||||
| String uuid = UUID.randomUUID().toString().replace("-", ""); | |||||
| for (int i = 0; i < 8; i++) { | |||||
| String str = uuid.substring(i * 4, i * 4 + 4); | |||||
| int x = Integer.parseInt(str, 16); | |||||
| shortBuffer.append(chars[x % 0x3E]); | |||||
| } | |||||
| return shortBuffer.toString(); | |||||
| } | |||||
| /** | |||||
| * <p> | |||||
| * 通过appId和内置关键词生成APP key | |||||
| * </P> | |||||
| */ | |||||
| public static String getAppKey(String appId) { | |||||
| try { | |||||
| String[] array = new String[]{appId, SERVER_NAME}; | |||||
| StringBuffer sb = new StringBuffer(); | |||||
| // 字符串排序 | |||||
| Arrays.sort(array); | |||||
| for (int i = 0; i < array.length; i++) { | |||||
| sb.append(array[i]); | |||||
| } | |||||
| String str = sb.toString(); | |||||
| MessageDigest md = MessageDigest.getInstance("SHA-1"); | |||||
| md.update(str.getBytes()); | |||||
| byte[] digest = md.digest(); | |||||
| StringBuffer hexstr = new StringBuffer(); | |||||
| String shaHex = ""; | |||||
| for (int i = 0; i < digest.length; i++) { | |||||
| shaHex = Integer.toHexString(digest[i] & 0xFF); | |||||
| if (shaHex.length() < 2) { | |||||
| hexstr.append(0); | |||||
| } | |||||
| hexstr.append(shaHex); | |||||
| } | |||||
| return hexstr.toString(); | |||||
| } catch (NoSuchAlgorithmException e) { | |||||
| e.printStackTrace(); | |||||
| throw new RuntimeException(); | |||||
| } | |||||
| } | |||||
| /** | |||||
| * <p> | |||||
| * | |||||
| * </P> | |||||
| */ | |||||
| public static String getSignKey(String appId,String appKey) { | |||||
| try { | |||||
| String[] array = new String[]{appId, appKey, SERVER_NAME,Long.toString(new Date().getTime())}; | |||||
| StringBuffer sb = new StringBuffer(); | |||||
| // 字符串排序 | |||||
| Arrays.sort(array); | |||||
| for (int i = 0; i < array.length; i++) { | |||||
| sb.append(array[i]); | |||||
| } | |||||
| String str = sb.toString(); | |||||
| MessageDigest md = MessageDigest.getInstance("SHA-1"); | |||||
| md.update(str.getBytes()); | |||||
| byte[] digest = md.digest(); | |||||
| StringBuffer hexstr = new StringBuffer(); | |||||
| String shaHex = ""; | |||||
| for (int i = 0; i < digest.length; i++) { | |||||
| shaHex = Integer.toHexString(digest[i] & 0xFF); | |||||
| if (shaHex.length() < 2) { | |||||
| hexstr.append(0); | |||||
| } | |||||
| hexstr.append(shaHex); | |||||
| } | |||||
| return hexstr.toString().toUpperCase(); | |||||
| } catch (NoSuchAlgorithmException e) { | |||||
| e.printStackTrace(); | |||||
| throw new RuntimeException(); | |||||
| } | |||||
| } | |||||
| public static void main(String[] args) { | |||||
| String appId = getAppId(); | |||||
| String appKey = getAppKey(appId); | |||||
| String signKey = getSignKey(appId,appKey); | |||||
| System.out.println("appId: "+appId); | |||||
| System.out.println("appKey: "+appKey); | |||||
| System.out.println("signKey: "+signKey); | |||||
| } | |||||
| } | |||||
| @@ -1,4 +1,4 @@ | |||||
| package com.iformall.utils.gooagoo; | |||||
| package com.iformall.utils.sign; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| @@ -0,0 +1,65 @@ | |||||
| <?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.WxThirdPartyApiMapper"> | |||||
| <resultMap id="BaseResultMap" type="com.iformall.domain.po.WxThirdPartyApi"> | |||||
| <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"/> | |||||
| <result column="tp_id" jdbcType="VARCHAR" property="tpId"/> | |||||
| </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`,`tp_id` | |||||
| </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.WxThirdPartyApi" resultMap="BaseResultMap"> | |||||
| select | |||||
| <include refid="allColumns"/> | |||||
| from wx_third_party_api | |||||
| <include refid="dynamicWhereConditions"/> | |||||
| </select> | |||||
| </mapper> | |||||