| | |
| | | private String corpId; |
| | | /**小程序appid*/ |
| | | private String mpId; |
| | | /**his账号的appid*/ |
| | | private String hisAppId; |
| | | |
| | | public String getCorpId() { |
| | | return corpId; |
| | |
| | | public void setMpId(String mpId) { |
| | | this.mpId = mpId; |
| | | } |
| | | |
| | | public String getHisAppId() { |
| | | return hisAppId; |
| | | } |
| | | |
| | | public void setHisAppId(String hisAppId) { |
| | | this.hisAppId = hisAppId; |
| | | } |
| | | } |
| | |
| | | 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; |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | <!-- 整个实体类修改,表字段=实体类字段--> |
| | | <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> |
| | | |
| | |
| | | <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" > |
| | |
| | | |
| | | <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> |
| | |
| | | @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() { |
| | | } |
| | | |
| | |
| | | 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; |
| | |
| | | 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; |
| | | } |
| | | } |
| | |
| | | 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; |
| | |
| | | String controllerPackRootResourse = "phi_platform_user.src.main.resources"; |
| | | |
| | | // 替换此处名字 |
| | | Class<?> clas = DeductionProject.class; |
| | | Class<?> clas = ApplyParameter.class; |
| | | |
| | | // 获取对象生成的上层包名 |
| | | String objectPackageName = clas.getPackage().getName(); |
New file |
| | |
| | | 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());*/ |
| | | } |
| | | |
| | | } |
File was renamed from phi_platform_user/src/main/java/com/hx/phip/controller/AccountTokenController.java |
| | |
| | | **/ |
| | | @RestController |
| | | @RequestMapping("/account_token") |
| | | public class AccountTokenController extends BaseController { |
| | | public class MpTokenController extends BaseController { |
| | | |
| | | @Resource |
| | | private CustomParameter customParameter; |
New file |
| | |
| | | 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); |
| | | |
| | | |
| | | } |
New file |
| | |
| | | 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; |
| | | } |
| | | } |