chenjiahe
2021-12-27 89085b3f5d8971a08aac4e0b804e9e505baa3c69
修改获取Token
1 文件已重命名
3个文件已添加
5个文件已修改
346 ■■■■■ 已修改文件
phi_platform_common/src/main/java/com/hx/phip/entity/AccountToken.java 10 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_common/src/main/java/com/hx/phip/tool/ApplyParameterTool.java 17 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_common/src/main/resources/mapper/ApplyParameterMapper.xml 8 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_model/src/main/java/com/hx/phip/model/ApplyParameter.java 49 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/AutoDomeUtil.java 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/controller/HisTokenController.java 123 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/controller/MpTokenController.java 2 ●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/service/ApplyParameterService.java 33 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_user/src/main/java/com/hx/phip/service/impl/ApplyParameterServiceImpl.java 101 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
phi_platform_common/src/main/java/com/hx/phip/entity/AccountToken.java
@@ -7,6 +7,8 @@
    private String corpId;
    /**小程序appid*/
    private String mpId;
    /**his账号的appid*/
    private String hisAppId;
    public String getCorpId() {
        return corpId;
@@ -23,4 +25,12 @@
    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
@@ -81,5 +81,22 @@
        return spplyParameter;
    }
    /**his账号
     * @param hisAppId
     * @param commonService
     * @return
     */
    public static ApplyParameter getHisAccount(String hisAppId, CommonService commonService){
        SqlSentence sqlSentence = new SqlSentence();
        Map<String,Object> values = new HashMap<>();
        values.put("isDel",ApplyParameter.NO);
        values.put("hisAppId",hisAppId);
        values.put("type",ApplyParameter.TYPE_HIS_ACCOUNT);
        sqlSentence.sqlSentence("SELECT * FROM pla_apply_parameter WHERE isDel = #{m.isDel} AND hisAppId = #{m.hisAppId} AND type = #{m.type}",values);
        ApplyParameter spplyParameter = commonService.selectOne(ApplyParameterMapper.class,sqlSentence);
        return spplyParameter;
    }
}
phi_platform_common/src/main/resources/mapper/ApplyParameterMapper.xml
@@ -8,7 +8,7 @@
    <!-- 整个实体类修改,表字段=实体类字段-->
    <sql id="Update_Column_All">
        <trim prefixOverrides=",">
            ,corpId = #{corpId},applySecretKey = #{applySecretKey},mpAppId = #{mpAppId},mpSecretKey = #{mpSecretKey},isDel = #{isDel},createTime = #{createTime}
            ,name = #{name},uniqueCode = #{uniqueCode},type = #{type},corpId = #{corpId},communiSecretKey = #{communiSecretKey},contactSecretKey = #{contactSecretKey},mpAppId = #{mpAppId},mpSecretKey = #{mpSecretKey},applySecretKey = #{applySecretKey},hisAppId = #{hisAppId},hisSecretKey = #{hisSecretKey},hisCode = #{hisCode},remarkInfo = #{remarkInfo},isDel = #{isDel},createTime = #{createTime}
        </trim>
    </sql>
     
@@ -19,7 +19,7 @@
        <selectKey keyProperty="id" resultType="String" order="BEFORE">
               select replace(uuid(),'-','') from dual
        </selectKey>
        insert into pla_apply_parameter (id,corpId,applySecretKey,mpAppId,mpSecretKey,isDel,createTime)  values (#{id},#{corpId},#{applySecretKey},#{mpAppId},#{mpSecretKey},#{isDel},#{createTime})
        insert into pla_apply_parameter (id,name,uniqueCode,type,corpId,communiSecretKey,contactSecretKey,mpAppId,mpSecretKey,applySecretKey,hisAppId,hisSecretKey,hisCode,remarkInfo,isDel,createTime)  values (#{id},#{name},#{uniqueCode},#{type},#{corpId},#{communiSecretKey},#{contactSecretKey},#{mpAppId},#{mpSecretKey},#{applySecretKey},#{hisAppId},#{hisSecretKey},#{hisCode},#{remarkInfo},#{isDel},#{createTime})
    </insert>
    <select id="selectList" resultType="com.hx.phip.model.ApplyParameter" parameterType="com.hx.mybatisTool.SqlSentence" >
@@ -51,14 +51,14 @@
    <select id="selectOneByKey" resultType="com.hx.phip.model.ApplyParameter" parameterType="java.lang.Object" >
        select 
            id,corpId,applySecretKey,mpAppId,mpSecretKey,isDel,createTime
            id,name,uniqueCode,type,corpId,communiSecretKey,contactSecretKey,mpAppId,mpSecretKey,applySecretKey,hisAppId,hisSecretKey,hisCode,remarkInfo,isDel,createTime
        from pla_apply_parameter
        WHERE id = #{value}
    </select>
    <select id="selectOneByKeyBlob" resultType="com.hx.phip.model.ApplyParameter" parameterType="java.lang.Object" >
        select 
            id,corpId,applySecretKey,mpAppId,mpSecretKey,isDel,createTime
            id,name,uniqueCode,type,corpId,communiSecretKey,contactSecretKey,mpAppId,mpSecretKey,applySecretKey,hisAppId,hisSecretKey,hisCode,remarkInfo,isDel,createTime
        from pla_apply_parameter
        WHERE id = #{value}
    </select>
phi_platform_model/src/main/java/com/hx/phip/model/ApplyParameter.java
@@ -34,6 +34,17 @@
    @Column(comment = "企业微信应用秘钥(AES加密)", length = 255, type = MySqlTypeConstant.VARCHAR)
    private String applySecretKey;
    //HIS信息
    @Column(comment = "HIS账号appId", length = 64, type = MySqlTypeConstant.VARCHAR)
    private String hisAppId;
    @Column(comment = "HIS账秘钥", length = 255, type = MySqlTypeConstant.VARCHAR)
    private String hisSecretKey;
    @Column(comment = "HIS账号code", length = 255, type = MySqlTypeConstant.VARCHAR)
    private String hisCode;
    @Column(comment = "备注信息", length = 255, type = MySqlTypeConstant.VARCHAR)
    private String remarkInfo;
    public ApplyParameter() {
    }
@@ -42,8 +53,10 @@
    public static final int TYPE_CORP_MP = 0;
    /**企业微信信息*/
    public static final int TYPE_CORP_COMMUNICATION = 1;
    /**其他*/
    public static final int TYPE_OTHER = 3;
    /**联系我*/
    //public static final int TYPE_CORP_CONTACT = 2;
    /**HIS账号信息*/
    public static final int TYPE_HIS_ACCOUNT = 3;
    public String getCorpId() {
        return corpId;
@@ -116,4 +129,36 @@
    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/AutoDomeUtil.java
@@ -7,6 +7,7 @@
import com.hx.phiappt.model.order.*;
import com.hx.phiappt.model.user.*;
import com.hx.phiappt.model.warehouse.*;
import com.hx.phip.model.ApplyParameter;
import com.hx.util.StringUtils;
import java.io.File;
@@ -31,7 +32,7 @@
        String controllerPackRootResourse = "phi_platform_user.src.main.resources";
        // 替换此处名字
        Class<?> clas = DeductionProject.class;
        Class<?> clas = ApplyParameter.class;
        // 获取对象生成的上层包名
        String objectPackageName = clas.getPackage().getName();
phi_platform_user/src/main/java/com/hx/phip/controller/HisTokenController.java
New file
@@ -0,0 +1,123 @@
package com.hx.phip.controller;
import com.alibaba.fastjson.JSONObject;
import com.hx.common.BaseController;
import com.hx.phip.common.wx.corp.WeiXinCorpMpUtil;
import com.hx.phip.common.wx.corp.WeiXinMpUtil;
import com.hx.phip.config.CustomParameter;
import com.hx.phip.entity.AccountToken;
import com.hx.phip.model.ApplyParameter;
import com.hx.phip.model.SysParameter;
import com.hx.phip.tool.ApplyParameterTool;
import com.hx.util.AesUtil;
import com.hx.util.DateUtil;
import com.hx.util.HttpServletRequestUtil;
import com.hx.util.StringUtils;
import com.platform.constants.PlatformPattern;
import com.platform.exception.PlatTipsException;
import com.platform.resultTool.PlatformCode;
import com.platform.resultTool.PlatformResult;
import com.platform.resultTool.SystemCode;
import org.apache.catalina.servlet4preview.http.HttpServletRequest;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
/**
 * 获取HIS账号token
 *
 * @USER: chenjiahe
 * @DATE: 2021/11/01
 **/
@RestController
@RequestMapping("/his/account-token")
public class HisTokenController extends BaseController {
    @Resource
    private CustomParameter customParameter;
    /**获取企业通讯录token*/
    @RequestMapping(value = "/communi/get_token",method = RequestMethod.POST)
    public PlatformResult communitionToken(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.getHisAppId())) {
            throw new PlatTipsException(PlatformCode.ERROR_PARAMETER_NULL,"his appId is required");
        }
        if(!PlatformPattern.PROD.equals(customParameter.getPlatformPattern())){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"成产环境获取TOKEN");
        }
        //获取应用数据
        ApplyParameter applyParameter = ApplyParameterTool.getHisAccount(accountToken.getHisAppId(),commonService);
        if(applyParameter == null){
            throw new PlatTipsException(PlatformCode.ERROR_TIPS,"his appId is error");
        }
        //TODO 获取his的token
        SysParameter sysParameter = WeiXinCorpMpUtil.getApplicationAccessToken(commonService,applyParameter.getCorpId(),AesUtil.aesDecryp(applyParameter.getCommuniSecretKey()));
        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",Integer.parseInt(sysParameter.getParamValue1()));
        data.put("expires_surplus",secondNum(sysParameter.getCreateTime(),Integer.parseInt(sysParameter.getParamValue1())));
        return PlatformResult.success(data);
    }
    /**
     * token剩余时间
     * @param createTime 获取时间
     * @param second 有效时间(秒)
     * @return
     */
    public static long secondNum(Date createTime, int second) {
        //需要判断一下是否过期
        Date newDate = new Date();
        long secondNum = (newDate.getTime() - createTime.getTime())/1000;
        secondNum = second - secondNum;
        if(secondNum < 0){
            secondNum = 0;
        }
        return secondNum;
    }
    public static void main(String[] args) {
        /*net.sf.json.JSONObject data = CorpMpUtil.getApplicationAccessToken("wx23a7c266dcd048aa", "Ged7KSLS2d-0y-aCI0LzIMnILbFA6M5HXBcOwV4fBIA");
        System.out.println("应用token:"+data.toString());
        WeiXinInfo weiXinInfo = com.hx.util.corp.CorpMpUtil.userInfo("123456",data.optString("access_token"));
        System.out.println("应用weiXinInfo:"+weiXinInfo.toString());
        data = CorpMpUtil.getApplicationAccessToken("wx23a7c266dcd048aa", "uwr3G0y_IaB0MtrOqFYdROxf457-Gvp9s9rXexyutho");
        System.out.println("通讯录token:"+data.toString());
        weiXinInfo = com.hx.util.corp.CorpMpUtil.userInfo("123456",data.optString("access_token"));
        System.out.println("通讯录weiXinInfo:"+weiXinInfo.toString());*/
    }
}
phi_platform_user/src/main/java/com/hx/phip/controller/MpTokenController.java
File was renamed from phi_platform_user/src/main/java/com/hx/phip/controller/AccountTokenController.java
@@ -36,7 +36,7 @@
 **/
@RestController
@RequestMapping("/account_token")
public class AccountTokenController extends BaseController {
public class MpTokenController extends BaseController {
    @Resource
    private CustomParameter customParameter;
phi_platform_user/src/main/java/com/hx/phip/service/ApplyParameterService.java
New file
@@ -0,0 +1,33 @@
package com.hx.phip.service;
import com.hx.phip.model.ApplyParameter;
import com.hx.mybatisTool.SqlSentence;
import java.util.List;
import java.util.Map;
public interface ApplyParameterService {
    int selectCount(SqlSentence sqlSentence);
    void insert(ApplyParameter applyParameter);
    List<ApplyParameter> selectList(SqlSentence sqlSentence);
    List<Map<String,Object>> selectListMap(SqlSentence sqlSentence);
    ApplyParameter selectOne(SqlSentence sqlSentence);
    Map<String,Object> selectOneMap(SqlSentence sqlSentence);
    ApplyParameter selectOneByKey(Object object);
    ApplyParameter selectOneByKeyBlob(Object object);
    void updateAll(ApplyParameter applyParameter);
    void updateWhere(SqlSentence sqlSentence);
    void deleteOne(String delId);
}
phi_platform_user/src/main/java/com/hx/phip/service/impl/ApplyParameterServiceImpl.java
New file
@@ -0,0 +1,101 @@
package com.hx.phip.service.impl;
import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.hx.exception.TipsException;
import com.hx.phip.dao.mapper.ApplyParameterMapper;
import com.hx.phip.model.ApplyParameter;
import com.hx.phip.service.ApplyParameterService;
import com.hx.mybatisTool.SqlSentence;
import java.util.List;
import java.util.Map;
@Transactional
@Service
public class ApplyParameterServiceImpl implements ApplyParameterService {
    @Resource
    private ApplyParameterMapper applyParameterMapper;
    /**查询列表*/
    @Override
    public List<ApplyParameter> selectList(SqlSentence sqlSentence) {
        return applyParameterMapper.selectList(sqlSentence);
    }
    /**查询列表*/
    @Override
    public List<Map<String,Object>> selectListMap(SqlSentence sqlSentence) {
        return applyParameterMapper.selectListMap(sqlSentence);
    }
    /**查询单个*/
    @Override
    public ApplyParameter selectOne(SqlSentence sqlSentence) {
        return applyParameterMapper.selectOne(sqlSentence);
    }
    /**查询单个*/
    @Override
    public Map<String,Object> selectOneMap(SqlSentence sqlSentence) {
        return applyParameterMapper.selectOneMap(sqlSentence);
    }
    /**查询单个,大数据不拿取*/
    @Override
    public ApplyParameter selectOneByKey(Object object) {
        return applyParameterMapper.selectOneByKey(object);
    }
    /**查询单个,大数据拿取*/
    @Override
    public ApplyParameter selectOneByKeyBlob(Object object) {
        return applyParameterMapper.selectOneByKeyBlob(object);
    }
    /**新增*/
    @Override
    public void insert(ApplyParameter applyParameter) {
        int count = applyParameterMapper.insert(applyParameter);
        if(count != 1) {
            throw new TipsException("新增失败!");
        }
    }
    /**修改*/
    @Override
    public void updateAll(ApplyParameter applyParameter) {
        int count = applyParameterMapper.updateAll(applyParameter);
        if(count!=1) {
            throw new TipsException("保存失败!");
        }
    }
    /**修改*/
    @Override
    public void updateWhere(SqlSentence sqlSentence) {
        int count = applyParameterMapper.updateWhere(sqlSentence);
        if(count!=1) {
            throw new TipsException("保存失败!");
        }
    }
    /**删除一个*/
    @Override
    public void deleteOne(String delId) {
        int count = applyParameterMapper.deleteById(delId);
        if(count!=1) {
            throw new TipsException("删除失败!");
        }
    }
    /**查询条数*/
    @Override
    public int selectCount(SqlSentence sqlSentence) {
        int count = applyParameterMapper.selectCount(sqlSentence);
        return count;
    }
}