phi_platform_common/src/main/java/com/hx/phip/entity/AccountToken.java
@@ -1,6 +1,8 @@ package com.hx.phip.entity; import lombok.Data; @Data public class AccountToken { /**企业id*/ @@ -9,28 +11,8 @@ private String mpId; /**his账号的appid*/ private String hisAppId; /**公众号的appid*/ private String weChatAppId; public String getCorpId() { return corpId; } public void setCorpId(String corpId) { this.corpId = corpId; } public String getMpId() { return mpId; } public void setMpId(String mpId) { this.mpId = mpId; } public String getHisAppId() { return hisAppId; } public void setHisAppId(String hisAppId) { this.hisAppId = hisAppId; } } phi_platform_common/src/main/java/com/hx/phip/tool/ApplyParameterTool.java
@@ -64,7 +64,7 @@ return spplyParameter; } /**企业小程序 /**企业小程序信息 * @param mpAppId * @param commonService * @return @@ -81,6 +81,23 @@ return spplyParameter; } /**公众号信息 * @param weChatAppId * @param commonService * @return */ public static ApplyParameter getWeChatParameter(String weChatAppId, CommonService commonService){ SqlSentence sqlSentence = new SqlSentence(); Map<String,Object> values = new HashMap<>(); values.put("isDel",ApplyParameter.NO); values.put("weChatAppId",weChatAppId); values.put("type",ApplyParameter.TYPE_WE_CHAT); sqlSentence.sqlSentence("SELECT * FROM pla_apply_parameter WHERE isDel = #{m.isDel} AND type = #{m.type} AND weChatAppId = #{m.weChatAppId} ",values); ApplyParameter spplyParameter = commonService.selectOne(ApplyParameterMapper.class,sqlSentence); return spplyParameter; } /**his账号 * @param hisAppId * @param commonService phi_platform_model/src/main/java/com/hx/phip/model/ApplyParameter.java
@@ -4,12 +4,14 @@ import com.gitee.sunchenbin.mybatis.actable.annotation.Table; import com.gitee.sunchenbin.mybatis.actable.constants.MySqlTypeConstant; import com.hx.phiappt.model.BaseEntity; import lombok.Data; /** * 应用数据 * */ @Table(name = "pla_apply_parameter") @Data public class ApplyParameter extends BaseEntity { @Column(comment = "名称", length = 64, type = MySqlTypeConstant.VARCHAR,isNull = false) @@ -19,6 +21,8 @@ @Column(comment = "数据类型", length = 3, type = MySqlTypeConstant.INT,isNull = false) private int type; /****企业微信信息*****/ @Column(comment = "企业微信id", length = 64, type = MySqlTypeConstant.VARCHAR) private String corpId; @@ -27,14 +31,23 @@ @Column(comment = "企业微信联系我秘钥(AES加密)", length = 255, type = MySqlTypeConstant.VARCHAR) private String contactSecretKey; /****公众号信息****/ @Column(comment = "公众号appId", length = 64, type = MySqlTypeConstant.VARCHAR) private String weChatAppId; @Column(comment = "公众号秘钥(AES加密)", length = 255, type = MySqlTypeConstant.VARCHAR) private String weChatSecretKey; /****小程序信息****/ @Column(comment = "小程序appId/其他应用id", length = 64, type = MySqlTypeConstant.VARCHAR) private String mpAppId; @Column(comment = "小程序秘钥(AES加密)", length = 255, type = MySqlTypeConstant.VARCHAR) private String mpSecretKey; @Column(comment = "企业微信应用秘钥(AES加密)", length = 255, type = MySqlTypeConstant.VARCHAR) @Column(comment = "企业微信应用/小程序秘钥(AES加密)", length = 255, type = MySqlTypeConstant.VARCHAR) private String applySecretKey; //HIS信息 /****HIS信息****/ @Column(comment = "HIS账号appId", length = 64, type = MySqlTypeConstant.VARCHAR) private String hisAppId; @Column(comment = "HIS账秘钥", length = 255, type = MySqlTypeConstant.VARCHAR) @@ -57,108 +70,7 @@ //public static final int TYPE_CORP_CONTACT = 2; /**HIS账号信息*/ public static final int TYPE_HIS_ACCOUNT = 3; /**公众号*/ public static final int TYPE_WE_CHAT= 4; public String getCorpId() { return corpId; } public void setCorpId(String corpId) { this.corpId = corpId; } public String getApplySecretKey() { return applySecretKey; } public void setApplySecretKey(String applySecretKey) { this.applySecretKey = applySecretKey; } public String getMpAppId() { return mpAppId; } public void setMpAppId(String mpAppId) { this.mpAppId = mpAppId; } public String getMpSecretKey() { return mpSecretKey; } public void setMpSecretKey(String mpSecretKey) { this.mpSecretKey = mpSecretKey; } public int getType() { return type; } public void setType(int type) { this.type = type; } public String getCommuniSecretKey() { return communiSecretKey; } public void setCommuniSecretKey(String communiSecretKey) { this.communiSecretKey = communiSecretKey; } public String getContactSecretKey() { return contactSecretKey; } public void setContactSecretKey(String contactSecretKey) { this.contactSecretKey = contactSecretKey; } public String getName() { return name; } public void setName(String name) { this.name = name; } public String getUniqueCode() { return uniqueCode; } public void setUniqueCode(String uniqueCode) { this.uniqueCode = uniqueCode; } public String getHisAppId() { return hisAppId; } public void setHisAppId(String hisAppId) { this.hisAppId = hisAppId; } public String getHisSecretKey() { return hisSecretKey; } public void setHisSecretKey(String hisSecretKey) { this.hisSecretKey = hisSecretKey; } public String getHisCode() { return hisCode; } public void setHisCode(String hisCode) { this.hisCode = hisCode; } public String getRemarkInfo() { return remarkInfo; } public void setRemarkInfo(String remarkInfo) { this.remarkInfo = remarkInfo; } } phi_platform_user/src/main/java/com/hx/phip/controller/MpTokenController.java
@@ -233,6 +233,54 @@ return PlatformResult.success(data); } /**获取公众号普通token*/ @RequestMapping(value = "/weChat/get_token",method = RequestMethod.POST) public PlatformResult WeChatToken(HttpServletRequest request) { //获取返回参数 String bodydata = HttpServletRequestUtil.getBody(request); if(StringUtils.isEmpty(bodydata)){ throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误"); } AccountToken accountToken = null; try{ accountToken = JSONObject.parseObject(bodydata,AccountToken.class); }catch (Exception e){ throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误"); } if(accountToken == null){ throw new PlatTipsException(PlatformCode.ERROR_BODY_DATA,"数据格式错误"); } if (StringUtils.isEmpty(accountToken.getWeChatAppId())) { throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"weChatAppId is required"); } if(!PlatformPattern.PROD.equals(customParameter.getPlatformPattern())){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"正式环境获取TOKEN"); } //获取应用数据 ApplyParameter applyParameter = ApplyParameterTool.getWeChatParameter(accountToken.getMpId(),commonService); if(applyParameter == null){ throw new PlatTipsException(PlatformCode.ERROR_TIPS,"weChatAppId is error"); } SysParameter sysParameter = WeiXinMpUtil.getAccessToken(commonService,applyParameter.getWeChatAppId(),AesUtil.aesDecryp(applyParameter.getWeChatSecretKey())); if(sysParameter == null){ throw new PlatTipsException(PlatformCode.ERROR_SYSTEM,"服务错误"+ SystemCode.ERROR_GET_CORP_TOKEN); } Map<String,Object> data = new HashMap<>(); data.put("access_token",sysParameter.getParamValue()); data.put("create_time",DateUtil.formatDate(sysParameter.getCreateTime(),"yyyy-MM-dd HH:mm:ss")); data.put("expires_in",secondNum(sysParameter.getCreateTime(),Integer.parseInt(sysParameter.getParamValue1()))); data.put("expires_surplus",secondNum(sysParameter.getCreateTime(),Integer.parseInt(sysParameter.getParamValue1()))); return PlatformResult.success(data); } /** * token剩余时间 * @param createTime 获取时间