Commit f44e6cc3 authored by mengbali153's avatar mengbali153

Merge remote-tracking branch 'origin/master' into master

# Conflicts:
#	cement-business/src/main/java/cn/wise/sc/cement/business/controller/NormProductionController.java
#	cement-business/src/main/java/cn/wise/sc/cement/business/controller/ReportController.java
#	cement-business/src/main/java/cn/wise/sc/cement/business/controller/WeiXinController.java
#	cement-business/src/main/java/cn/wise/sc/cement/business/model/IndustrialReport.java
#	cement-business/src/main/java/cn/wise/sc/cement/business/model/SixElementReport.java
#	cement-business/src/main/java/cn/wise/sc/cement/business/model/query/CheckCountSampleQuery.java
#	cement-business/src/main/java/cn/wise/sc/cement/business/service/INormProductionService.java
#	cement-business/src/main/java/cn/wise/sc/cement/business/service/impl/CommonServiceImpl.java
#	cement-business/src/main/java/cn/wise/sc/cement/business/service/impl/EntrustServiceImpl.java
#	cement-business/src/main/java/cn/wise/sc/cement/business/service/impl/NormProductionServiceImpl.java
#	cement-business/src/main/java/cn/wise/sc/cement/business/service/impl/QualityApplyServiceImpl.java
#	cement-business/src/main/java/cn/wise/sc/cement/business/service/impl/WeiXinService.java
#	cement-business/src/main/java/cn/wise/sc/cement/business/util/CheckCountUtil.java
#	cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/Global.java
#	cement-business/src/main/java/cn/wise/sc/cement/business/util/weixin/WeixinInterfaceUtil.java
parents 1baf88a6 6a2b08fd
package cn.wise.sc.cement.business.controller; package cn.wise.sc.cement.business.controller;
import cn.hutool.core.util.StrUtil;
import cn.wise.sc.cement.business.model.BaseResponse; import cn.wise.sc.cement.business.model.BaseResponse;
import cn.wise.sc.cement.business.service.impl.WeiXinService; import cn.wise.sc.cement.business.service.impl.WeiXinService;
import cn.wise.sc.cement.business.wrapper.WrapMapper;
import cn.wise.sc.cement.business.wrapper.Wrapper;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
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;
...@@ -13,73 +13,116 @@ import org.springframework.web.bind.annotation.GetMapping; ...@@ -13,73 +13,116 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletRequest; import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
@Api(tags = "微信接口") @Api(tags = "微信接口")
@RestController @RestController
@RequestMapping("/tcdri/weixin") @RequestMapping("/tcdri/weixin")
public class WeiXinController { public class WeiXinController {
private static final Logger log = LoggerFactory.getLogger("WeiXinController"); private static final Logger log = LoggerFactory.getLogger("WeiXinController");
@Autowired
private WeiXinService weiXinService;
@ApiOperation(value = "获取登录token-小程序端")
@GetMapping("/getToken")
public BaseResponse getToken(String code) {
try {
return weiXinService.getToken(code, "APP");
} catch (Exception e) {
log.debug("获取登录token{}", e);
}
return BaseResponse.errorMsg("失败!");
}
@ApiOperation(value = "获取登录token-管理端")
@GetMapping("/getPCToken")
public BaseResponse getPCToken(String code) {
try {
return weiXinService.getToken(code, "PC");
} catch (Exception e) {
log.debug("获取登录token{}", e);
}
return BaseResponse.errorMsg("失败!");
}
@ApiOperation(value = "获取accessToken信息-小程序端")
@GetMapping("/getAccessToken")
public BaseResponse getAccessToken() {
try {
String accessToken = weiXinService.getAccessToken();
return BaseResponse.okData(accessToken);
} catch (Exception e) {
log.debug("获取accessToken信息-小程序端{}", e);
}
return BaseResponse.errorMsg("失败!");
}
@ApiOperation(value = "获取accessToken信息-管理端")
@GetMapping("/getPCAccessToken")
public BaseResponse getPCAccessToken() {
try {
String accessToken = weiXinService.getPCAccessToken();
return BaseResponse.okData(accessToken);
} catch (Exception e) {
log.debug("获取accessToken信息-管理端{}", e);
}
return BaseResponse.errorMsg("失败!");
}
@ApiOperation(value = "当前登录用户")
@GetMapping("/getLoginUser")
public BaseResponse getLoginUser() {
try {
return weiXinService.getLoginUser();
} catch (Exception e) {
log.debug("当前登录用户{}", e);
}
return BaseResponse.errorMsg("失败!");
}
@Autowired
private WeiXinService weiXinService;
@ApiOperation(value = "获取登录token-小程序端")
@GetMapping("/getToken")
public BaseResponse getToken(String code) {
log.debug("============================================");
log.debug("code: {}", code);
log.debug("=============================================");
try {
return weiXinService.getToken(code, "APP");
} catch (Exception e) {
log.debug("获取登录token{}", e);
}
return BaseResponse.errorMsg("失败!");
}
@ApiOperation(value = "获取登录token-管理端")
@GetMapping("/getPCToken")
public BaseResponse getPCToken(String code) {
try {
return weiXinService.getToken(code, "PC");
} catch (Exception e) {
log.debug("获取登录token{}", e);
}
return BaseResponse.errorMsg("失败!");
}
@ApiOperation(value = "当前登录用户")
@GetMapping("/getLoginUser")
public BaseResponse getLoginUser() {
try {
return weiXinService.getLoginUser();
} catch (Exception e) {
log.debug("当前登录用户{}", e);
}
return BaseResponse.errorMsg("失败!");
}
@GetMapping("/jsapiTicket")
@ApiOperation("获取jsapi_ticket")
public BaseResponse<Map> getAccessToken() {
String accessToken = weiXinService.getJsapiTicket();
Map<String, String> rts = new HashMap<>(5);
rts.put("jsapi_ticket", accessToken);
rts.put("timestamp", (new Date()).getTime() / 1000 + "");
rts.put("noncestr", "Wm3WZYTPz0wzccnW");
rts.put("app_id", "ww348f91b2573c1867");
rts.put("jsApiList","['scanQRCode']");
return BaseResponse.okData(rts);
}
@GetMapping("/signature")
@ApiOperation("获取accessToken")
public BaseResponse<String> signature(String param) {
MessageDigest md;
String tmpStr = null;
try {
md = MessageDigest.getInstance("SHA-1");
byte[] digest = md.digest(param.getBytes());
tmpStr = byteToStr(digest);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return BaseResponse.okData(StrUtil.swapCase(tmpStr));
}
/**
* 将字节数组转换为十六进制字符串
*
* @param byteArray
* @return
*/
private static String byteToStr(byte[] byteArray) {
String strDigest = "";
for (int i = 0; i < byteArray.length; i++) {
strDigest += byteToHexStr(byteArray[i]);
}
return strDigest;
}
/**
* 将字节转换为十六进制字符串
*
* @param mByte
* @return
*/
private static String byteToHexStr(byte mByte) {
char[] Digit = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
char[] tempArr = new char[2];
tempArr[0] = Digit[(mByte >>> 4) & 0X0F];
tempArr[1] = Digit[mByte & 0X0F];
String s = new String(tempArr);
return s;
}
} }
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
<select id="getSampleSixElementCheck" resultType="cn.wise.sc.cement.business.model.SixElementReport"> <select id="getSampleSixElementCheck" resultType="cn.wise.sc.cement.business.model.SixElementReport">
SELECT * FROM (SELECT count_result,entrust_id,team_group_name,sct.sample_id FROM sample_check sc SELECT * FROM (SELECT count_results,entrust_id,team_group_name,sct.sample_id FROM sample_check sc
LEFT JOIN LEFT JOIN
(SELECT check_id,sample_id FROM sample_check_team) sct (SELECT check_id,sample_id FROM sample_check_team) sct
ON sct.check_id = sc.id ON sct.check_id = sc.id
...@@ -14,12 +14,12 @@ ...@@ -14,12 +14,12 @@
(SELECT cement_code,sample_code,sample_form,`name` as sample_name,weight,id (SELECT cement_code,sample_code,sample_form,`name` as sample_name,weight,id
FROM sample) s FROM sample) s
ON s.id = sscct.sample_id AND entrust_id = #{entrustId} ON s.id = sscct.sample_id AND entrust_id = #{entrustId}
WHERE count_result IS NOT NULL; WHERE count_results IS NOT NULL;
</select> </select>
<select id="getSampleIndustrialCheck" resultType="cn.wise.sc.cement.business.model.IndustrialReport"> <select id="getSampleIndustrialCheck" resultType="cn.wise.sc.cement.business.model.IndustrialReport">
SELECT * FROM (SELECT count_result,entrust_id,team_group_name,sct.sample_id FROM sample_check sc SELECT * FROM (SELECT count_results,entrust_id,team_group_name,sct.sample_id FROM sample_check sc
LEFT JOIN LEFT JOIN
(SELECT check_id,sample_id FROM sample_check_team) sct (SELECT check_id,sample_id FROM sample_check_team) sct
ON sct.check_id = sc.id ON sct.check_id = sc.id
...@@ -29,7 +29,6 @@ ...@@ -29,7 +29,6 @@
(SELECT cement_code,sample_code,sample_form,`name` as sample_name,weight,id (SELECT cement_code,sample_code,sample_form,`name` as sample_name,weight,id
FROM sample) s FROM sample) s
ON s.id = sscct.sample_id AND entrust_id = #{entrustId} ON s.id = sscct.sample_id AND entrust_id = #{entrustId}
WHERE count_result IS NOT NULL; WHERE count_results IS NOT NULL;
</select> </select>
</mapper> </mapper>
package cn.wise.sc.cement.business.model; package cn.wise.sc.cement.business.model;
import lombok.Data; import lombok.Data;
import java.io.Serializable; import java.io.Serializable;
/** /**
...@@ -12,45 +11,45 @@ import java.io.Serializable; ...@@ -12,45 +11,45 @@ import java.io.Serializable;
@Data @Data
public class IndustrialReport implements Serializable { public class IndustrialReport implements Serializable {
private static final long serialVersionUID = 42L; private static final long serialVersionUID = 42L;
/** /**
* 样品名称 * 样品名称
*/ */
private String sampleName; private String sampleName;
/** /**
* 来样状态 * 来样状态
*/ */
private String sampleForm; private String sampleForm;
/** /**
* 来样编号 * 来样编号
*/ */
private String sampleCode; private String sampleCode;
/** /**
* 样品重量 * 样品重量
*/ */
private String weight; private String weight;
/** /**
* 本所编号 * 本所编号
*/ */
private String cementCode; private String cementCode;
/** /**
* 校核数据 * 校核数据
*/ */
private String countResult; private String countResults;
//下面是工业特性得检测项 //下面是工业特性得检测项
private String mad; private String mad;
private String aad; private String aad;
private String vad; private String vad;
private String mjkg; private String mjkg;
private String jz; private String jz;
private String qnetstad; private String qnetstad;
private String stad; private String stad;
} }
package cn.wise.sc.cement.business.model;
/**
* @author: Seven.wk
* @description: 数据返回类
* @create: 2018/07/04
*/
public class ResultVO<T> {
private Integer code;
private String message;
private T data;
public ResultVO() {
}
public ResultVO(Integer code, String message) {
this.code = code;
this.message = message;
}
public ResultVO(Integer code, String message, T data) {
this.code = code;
this.message = message;
this.data = data;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
public T getData() {
return data;
}
public void setData(T data) {
this.data = data;
}
}
...@@ -12,54 +12,54 @@ import java.io.Serializable; ...@@ -12,54 +12,54 @@ import java.io.Serializable;
@Data @Data
public class SixElementReport implements Serializable { public class SixElementReport implements Serializable {
private static final long serialVersionUID = 42L; private static final long serialVersionUID = 42L;
/** /**
* 样品名称 * 样品名称
*/ */
private String sampleName; private String sampleName;
/** /**
* 来样状态 * 来样状态
*/ */
private String sampleForm; private String sampleForm;
/** /**
* 来样编号 * 来样编号
*/ */
private String sampleCode; private String sampleCode;
/** /**
* 样品重量 * 样品重量
*/ */
private String weight; private String weight;
/** /**
* 本所编号 * 本所编号
*/ */
private String cementCode; private String cementCode;
/** /**
* 校核数据 * 校核数据
*/ */
private String countResult; private String countResults;
//下面为六元素 //下面为六元素
private String loi = ""; private String loi ="";
private String sio2 = ""; private String sio2 ="";
private String fe2o3 = ""; private String fe2o3 ="";
private String cao = ""; private String cao ="";
private String mgo = ""; private String mgo ="";
private String so3 = ""; private String so3 ="";
private String cl = ""; private String cl="";
//情况一:Al2O3(含TiO3) //情况一:Al2O3(含TiO3)
private String al2o3AndTio2 = ""; private String al2o3AndTio2 ="";
//情况二:Al2O3和TiO3单独分开 //情况二:Al2O3和TiO3单独分开
private String al2o3 = ""; private String al2o3 ="";
private String tio2 = ""; private String tio2 ="";
} }
...@@ -24,106 +24,102 @@ import java.util.List; ...@@ -24,106 +24,102 @@ import java.util.List;
*/ */
public interface INormProductionService extends IService<NormProduction> { public interface INormProductionService extends IService<NormProduction> {
/** /**
* 创建新的标准产值配置 * 创建新的标准产值配置
* *
* @param normProduction 标准产值 * @param normProduction 标准产值
* @return BaseResponse * @return BaseResponse
*/ */
BaseResponse<NormProduction> addObj(NormProduction normProduction); BaseResponse<NormProduction> addObj(NormProduction normProduction);
/** /**
* 分页查询 * 分页查询
* *
* @param pageQuery 分页条件 * @param pageQuery 分页条件
* @return 数据 * @return 数据
*/ */
BaseResponse<IPage<NormProductionVo>> getPage(PageQuery pageQuery); BaseResponse<IPage<NormProductionVo>> getPage(PageQuery pageQuery);
/** /**
* 编辑标准产值 * 编辑标准产值
* *
* @param production 标准产值 * @param production 标准产值
* @return bool * @return bool
*/ */
BaseResponse<Boolean> edit(NormProduction production); BaseResponse<Boolean> edit(NormProduction production);
/** /**
* 启用禁用标准产值 * 启用禁用标准产值
* *
* @param id id * @param id id
* @return bool * @return bool
*/ */
BaseResponse<Integer> activeOrForbidden(Integer id); BaseResponse<Integer> activeOrForbidden(Integer id);
/** /**
* 标准产值统计 * 标准产值统计
* *
* @param start 开始时间 * @param start 开始时间
* @param end 结束时间 * @param end 结束时间
* @param groupId 部门id * @param groupId 部门id
* @return BaseResponse * @return BaseResponse
*/ */
BaseResponse<List<NormProductionStatistics>> normProductionStatistics(Long start, Long end, String name, Integer groupId); BaseResponse<List<NormProductionStatistics>> normProductionStatistics(Long start, Long end, String name, Integer groupId);
/** /**
* 标准产值统计 单人详情 * 标准产值统计 单人详情
* *
* @param userId 用户id * @param userId 用户id
* @param start 开始时间 * @param start 开始时间
* @param end 结束时间 * @param end 结束时间
* @return 详细信息 * @return 详细信息
*/ */
List<NormProduction.NormProductionDetail> normProductionDetails(Integer userId, List<NormProduction.NormProductionDetail> normProductionDetails(Integer userId,
Long start, Long end); Long start, Long end);
/** /**
* 总产值统计 * 总产值统计
* *
* @param name 用户 * @param name 用户
* @param start 开始时间 * @param start 开始时间
* @param end 结束时间 * @param end 结束时间
* @return 详细信息 * @return 详细信息
*/ */
List<ProductionVo> production(String name, Long start, Long end, Integer groupId); List<ProductionVo> production(String name,Long start,Long end,Integer groupId);
/** /**
* 导出标准统计 * 导出标准统计
* * @param start 开始时间
* @param start 开始时间 * @param end 结束时间
* @param end 结束时间 * @param name 人员名字
* @param name 人员名字 * @param groupId 部门id
* @param groupId 部门id * @param response 响应体
* @param response 响应体 */
*/ void exportNormProductionStatistics(Long start, Long end,String name,Integer groupId, HttpServletResponse response);
void exportNormProductionStatistics(Long start, Long end, String name, Integer groupId, HttpServletResponse response);
/** /**
* 导出个人标准产值详情列表 * 导出个人标准产值详情列表
* * @param userId 用户id
* @param userId 用户id * @param startTime 开始时间
* @param startTime 开始时间 * @param endTime 结束时间
* @param endTime 结束时间 * @param response 响应体
* @param response 响应体 */
*/ void exportNormProductionDetail(Integer userId, Long startTime, Long endTime, HttpServletResponse response);
void exportNormProductionDetail(Integer userId, Long startTime, Long endTime, HttpServletResponse response);
/** /**
* 导出产值总统计列表 * 导出产值总统计列表
* * @param name 名字检索
* @param name 名字检索 * @param startTime 开始时间
* @param startTime 开始时间 * @param endTime 结束时间
* @param endTime 结束时间 * @param response 响应体
* @param response 响应体 */
*/ void exportProduction(String name, Long startTime, Long endTime,Integer groupId,HttpServletResponse response);
void exportProduction(String name, Long startTime, Long endTime, Integer groupId, HttpServletResponse response);
/** /**
* 统计工作量 * 统计工作量
* * @param startTime 开始时间
* @param startTime 开始时间 * @param endTime 结束时间
* @param endTime 结束时间 * @return 统计对象
* @return 统计对象 */
*/ List<WorkloadStatisticsVo> workloadStatistics(Date startTime, Date endTime,Integer userId);
List<WorkloadStatisticsVo> workloadStatistics(Date startTime, Date endTime);
} }
...@@ -25,31 +25,34 @@ import java.util.Map; ...@@ -25,31 +25,34 @@ import java.util.Map;
@Service @Service
public class WeiXinService { public class WeiXinService {
@Value("${weixin.corpid}") @Value("${weixin.corpid}")
private String corpid; private String corpid;
@Value("${weixin.corpsecret}") @Value("${weixin.corpsecret}")
private String corpsecret; private String corpsecret;
@Value("${weixin.corpsecretPC}") @Value("${weixin.corpsecretPC}")
private String corpsecretPC; private String corpsecretPC;
@Autowired @Autowired
private ISysUserService userService; private ISysUserService userService;
@Autowired @Autowired
RedisUtil redisUtil; RedisUtil redisUtil;
/** final static String ACCESS_TOKEN = "ACCESS_TOKEN";
* 获取登录token final static String JSAPITICKET = "JSAPITICKET";
*
* @param code /**
* @param type PC管理端 APP小程序端 * 获取登录token
* @return *
*/ * @param code
public BaseResponse<String> getToken(String code, String type) { * @param type PC管理端 APP小程序端
if (StrUtil.isEmpty(code)) { * @return
return BaseResponse.errorMsg("code为必填项!"); */
} public BaseResponse<String> getToken(String code, String type) {
System.out.println("==================code==================="); if (StrUtil.isEmpty(code)) {
System.out.println(code); return BaseResponse.errorMsg("code为必填项!");
try { }
System.out.println("==================code===================");
System.out.println(code);
try {
/*String accessToken = null; /*String accessToken = null;
if(type.equals("PC")){ if(type.equals("PC")){
accessToken = getAccessToken(); accessToken = getAccessToken();
...@@ -68,81 +71,114 @@ public class WeiXinService { ...@@ -68,81 +71,114 @@ public class WeiXinService {
System.out.println("==================UserId==================="); System.out.println("==================UserId===================");
System.out.println(UserId); System.out.println(UserId);
JSONObject userJson = getUser(accessToken, UserId);*/ JSONObject userJson = getUser(accessToken, UserId);*/
QueryWrapper<SysUser> wrapper = new QueryWrapper<>(); QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
// wrapper.eq("phone", userJson.get("mobile")); // wrapper.eq("phone", userJson.get("mobile"));
wrapper.eq("phone", code); //暂时用手机号代替code wrapper.eq("phone", code); //暂时用手机号代替code
SysUser sysUser = userService.getOne(wrapper); SysUser sysUser = userService.getOne(wrapper);
if (sysUser == null) { if (sysUser == null) {
return BaseResponse.errorMsg("非系统用户不允许登录!"); return BaseResponse.errorMsg("非系统用户不允许登录!");
} }
if (sysUser.getStatus() == 0) { if (sysUser.getStatus() == 0) {
return BaseResponse.errorMsg("用户被禁用!"); return BaseResponse.errorMsg("用户被禁用!");
} }
if (sysUser.getIsDelete() == 0) { if (sysUser.getIsDelete() == 0) {
return BaseResponse.errorMsg("用户被删除!"); return BaseResponse.errorMsg("用户被删除!");
} }
//生成token,存入redis //生成token,存入redis
String token = JwtUtil.createToken(sysUser.getId(), sysUser.getUsername(), String token = JwtUtil.createToken(sysUser.getId(), sysUser.getUsername(),
sysUser.getName(), sysUser.getPhone()); sysUser.getName(), sysUser.getPhone());
System.out.println(token); System.out.println(token);
redisUtil.setString(sysUser.getId().toString(), token, 3600); redisUtil.setString(sysUser.getId().toString(), token, 3600);
return BaseResponse.okData(token); return BaseResponse.okData(token);
} catch (Exception e) { } catch (Exception e) {
return BaseResponse.errorMsg(e.getMessage()); return BaseResponse.errorMsg(e.getMessage());
} }
} }
//获取accessToken信息 //获取accessToken信息
public String getAccessToken() { public String getAccessToken() {
try { try {
String param = "corpid=%s&corpsecret=%s"; String param = "corpid=%s&corpsecret=%s";
param = String.format(param, corpid, corpsecret); param = String.format(param, corpid, corpsecret);
JSONObject jsonObject = WeixinInterfaceUtil.doGet(Global.ACCESSTOKENURL, param); JSONObject jsonObject = WeixinInterfaceUtil.doGet(Global.ACCESSTOKENURL, param);
String accessToken = jsonObject.getString("access_token"); String accessToken = jsonObject.getString("access_token");
System.out.println("==================accessToken==================="); System.out.println("==================accessToken===================");
System.out.println(accessToken); System.out.println(accessToken);
return accessToken; return accessToken;
} catch (Exception e) { } catch (Exception e) {
return null; return null;
} }
} }
public String getPCAccessToken() { //获取accessToken信息
try { public String getJsapiTicket() {
String param = "corpid=%s&corpsecret=%s"; try {
param = String.format(param, corpid, corpsecretPC); String accessToken;
JSONObject jsonObject = WeixinInterfaceUtil.doGet(Global.ACCESSTOKENURL, param); String jsapiTicket;
String accessToken = jsonObject.getString("access_token"); if (!redisUtil.existsKey(ACCESS_TOKEN)) {
System.out.println("==================accessToken==================="); String param = "corpid=%s&corpsecret=%s";
System.out.println(accessToken); param = String.format(param, corpid, corpsecret);
return accessToken; JSONObject jsonObject = WeixinInterfaceUtil.doGet(Global.ACCESSTOKENURL, param);
} catch (Exception e) { accessToken = jsonObject.getString("access_token");
return null; redisUtil.setString(ACCESS_TOKEN, accessToken, 7200);
} }
} accessToken = redisUtil.getString(ACCESS_TOKEN) + "";
System.out.println("==================accessToken===================");
//获取用户信息 System.out.println(accessToken);
public JSONObject getUser(String accessToken, String userId) {
try { if (!redisUtil.existsKey(JSAPITICKET)) {
String param = "access_token=%s&userid=%s"; String param3 = "access_token=%s&type=agent_config";
param = String.format(param, accessToken, userId); param3 = String.format(param3, accessToken);
JSONObject jsonObject = WeixinInterfaceUtil.doGet(Global.USERURL, param); JSONObject ticketJsonObject = WeixinInterfaceUtil.doGet(Global.userTicket, param3);
System.out.println("==================jsonObject==================="); jsapiTicket = ticketJsonObject.getString("ticket");
System.out.println(jsonObject); redisUtil.setString(JSAPITICKET, jsapiTicket, 7200);
return jsonObject; }
} catch (Exception e) {
return null; jsapiTicket = redisUtil.getString(JSAPITICKET) + "";
} return jsapiTicket;
} } catch (Exception e) {
return null;
/** }
* 当前登录用户 }
*
* @return public String getPCAccessToken() {
*/ try {
public BaseResponse<LoginUser> getLoginUser() { String param = "corpid=%s&corpsecret=%s";
LoginUser loginUser = userService.getLoginUser(); param = String.format(param, corpid, corpsecretPC);
return BaseResponse.okData(loginUser); JSONObject jsonObject = WeixinInterfaceUtil.doGet(Global.ACCESSTOKENURL, param);
} String accessToken = jsonObject.getString("access_token");
System.out.println("==================accessToken===================");
System.out.println(accessToken);
return accessToken;
} catch (Exception e) {
return null;
}
}
//获取用户信息
public JSONObject getUser(String accessToken, String userId) {
try {
String param = "access_token=%s&userid=%s";
param = String.format(param, accessToken, userId);
JSONObject jsonObject = WeixinInterfaceUtil.doGet(Global.USERURL, param);
System.out.println("==================jsonObject===================");
System.out.println(jsonObject);
return jsonObject;
} catch (Exception e) {
return null;
}
}
/**
* 当前登录用户
*
* @return
*/
public BaseResponse<LoginUser> getLoginUser() {
LoginUser loginUser = userService.getLoginUser();
return BaseResponse.okData(loginUser);
}
} }
...@@ -4,7 +4,6 @@ import org.apache.commons.io.FilenameUtils; ...@@ -4,7 +4,6 @@ import org.apache.commons.io.FilenameUtils;
import org.csource.common.MyException; import org.csource.common.MyException;
import org.csource.common.NameValuePair; import org.csource.common.NameValuePair;
import org.csource.fastdfs.*; import org.csource.fastdfs.*;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
......
...@@ -3,10 +3,9 @@ package cn.wise.sc.cement.business.util.weixin; ...@@ -3,10 +3,9 @@ package cn.wise.sc.cement.business.util.weixin;
/** /**
* 功能说明:企业微信全局接口地址 * 功能说明:企业微信全局接口地址
* 修改说明: * 修改说明:
*
* @author zhenglibing * @author zhenglibing
* @version 0.1
* @date 2018年1月8日 下午2:27:43 * @date 2018年1月8日 下午2:27:43
* @version 0.1
*/ */
public interface Global { public interface Global {
...@@ -17,16 +16,29 @@ public interface Global { ...@@ -17,16 +16,29 @@ public interface Global {
*/ */
public static final String ACCESSTOKENURL = "https://qyapi.weixin.qq.com/cgi-bin/gettoken"; public static final String ACCESSTOKENURL = "https://qyapi.weixin.qq.com/cgi-bin/gettoken";
/** /**
* 微信公众平台,获取访问用户身份的接口地址,Https请求方式:GET * 微信公众平台,获取访问用户身份的接口地址,Https请求方式:GET
* 接口地址示例:https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=ACCESS_TOKEN&code=CODE * 接口地址示例:https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=ACCESS_TOKEN&code=CODE
*/ */
public static final String USERINFOURL = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo"; public static final String USERINFOURL = "https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo";
/** /**
* 微信公众平台,获取访问用户信息的接口地址,Https请求方式:GET * 微信公众平台,获取访问用户信息的接口地址,Https请求方式:GET
* 接口地址示例:https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&userid=USERID * 接口地址示例:https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=ACCESS_TOKEN&userid=USERID
*/ */
public static final String USERURL = "https://qyapi.weixin.qq.com/cgi-bin/user/get"; public static final String USERURL = "https://qyapi.weixin.qq.com/cgi-bin/user/get";
public static final String ticket = "https://qyapi.weixin.qq.com/cgi-bin/get_jsapi_ticket";
/**
* 微信公众平台,发送应用消息的接口地址,Https请求方式:GET
* 接口地址示例:https://qyapi.weixin.qq.com/cgi-bin/message/send?access_token=ACCESS_TOKEN
*/
public static final String SENDMESSAGE = "https://qyapi.weixin.qq.com/cgi-bin/message/send";
public static final String userTicket = "https://qyapi.weixin.qq.com/cgi-bin/ticket/get";
} }
package cn.wise.sc.cement.business.util.weixin; package cn.wise.sc.cement.business.util.weixin;
import cn.wise.sc.cement.business.model.ResultVO;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.http.*;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate; import org.springframework.web.client.RestTemplate;
import java.util.*; import java.util.*;
/** /**
* 艺哚哚对外开放接口 工具类 * 对外开放接口 工具类
*/ */
public class WeixinInterfaceUtil { public class WeixinInterfaceUtil {
private static final String HOST = "https://ydd.whlyj.sh.gov.cn/"; //服务器IP与端口 private static final String HOST = "https://ydd.whlyj.sh.gov.cn/"; //服务器IP与端口
private static final String APPID = "DSACTSYS"; private static final String APPID = "DSACTSYS";
private static final String APPSECRET = "uzRpwnG6USeZDR0C"; private static final String APPSECRET = "uzRpwnG6USeZDR0C";
// private static final Long TIMESTAMP = System.currentTimeMillis(); // private static final Long TIMESTAMP = System.currentTimeMillis();
private static final String NONCE = UUID.randomUUID().toString(); private static final String NONCE = UUID.randomUUID().toString();
public static void main(String[] args) {
public static void main(String[] args){
String param = "corpid=%s&corpsecret=%s"; String param = "corpid=%s&corpsecret=%s";
param = String.format(param, "ww348f91b2573c1867", "gFa_7XvXtCaoeAYERzjRwwz_OTJkJfgBb8weOKjmI3o"); param = String.format(param, "ww348f91b2573c1867", "gFa_7XvXtCaoeAYERzjRwwz_OTJkJfgBb8weOKjmI3o");
try { try {
...@@ -30,19 +37,40 @@ public class WeixinInterfaceUtil { ...@@ -30,19 +37,40 @@ public class WeixinInterfaceUtil {
e.printStackTrace(); e.printStackTrace();
} }
} }
public static JSONObject doGet(String url, String param) { public static JSONObject doGet(String url, String param) {
String path = url + "?" + param; String path= url+"?"+ param;
RestTemplate restTemplate = new RestTemplate(); RestTemplate restTemplate = new RestTemplate();
JSONObject resultMap = restTemplate.getForObject(path, JSONObject.class); JSONObject resultMap = restTemplate.getForObject(path,JSONObject.class);
return resultMap; return resultMap;
} }
/**
* 向目的URL发送post请求
* @param url 目的url
* @param params 发送的参数
* @return ResultVO
*/
public static ResultVO sendPostRequest(String url, MultiValueMap<String, String> params){
RestTemplate client = new RestTemplate();
HttpHeaders headers = new HttpHeaders();
HttpMethod method = HttpMethod.POST;
// 以表单的方式提交
headers.setContentType(MediaType.APPLICATION_FORM_URLENCODED);
//将请求头部和参数合成一个请求
HttpEntity<MultiValueMap<String, String>> requestEntity = new HttpEntity<>(params, headers);
//执行HTTP请求,将返回的结构使用ResultVO类格式化
ResponseEntity<ResultVO> response = client.exchange(url, method, requestEntity, ResultVO.class);
return response.getBody();
}
/** /**
* 将请求参数放到map里, * 将请求参数放到map里,
* 按照字母请求参数名的字母升序排列非空请求参数(包含 appid) * 按照字母请求参数名的字母升序排列非空请求参数(包含 appid)
*
* @param sortedParams * @param sortedParams
* @return * @return
*/ */
...@@ -68,4 +96,6 @@ public class WeixinInterfaceUtil { ...@@ -68,4 +96,6 @@ public class WeixinInterfaceUtil {
return content.toString(); return content.toString();
} }
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment