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
......@@ -223,9 +223,10 @@ public class NormProductionController {
iNormProductionService.exportProduction(name, startTime, endTime, groupId, response);
}
@GetMapping("/workload/statistics")
@ApiOperation("工作量统计")
public BaseResponse<List<WorkloadStatisticsVo>> workloadStatistics(String start, String end) {
public BaseResponse<List<WorkloadStatisticsVo>> workloadStatistics(String start, String end, Integer userId) {
Date startTime = null;
Date endTime = DateUtil.date();
......@@ -234,7 +235,7 @@ public class NormProductionController {
endTime = DateUtil.parseDate(end);
}
return BaseResponse.okData(iNormProductionService.workloadStatistics(startTime, endTime));
return BaseResponse.okData(iNormProductionService.workloadStatistics(startTime, endTime, userId));
}
}
......
......@@ -25,7 +25,6 @@ import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpServletResponse;
import java.util.HashMap;
import java.util.List;
......@@ -91,7 +90,7 @@ public class ReportController {
//首页及封面导出
ReportDetailVo rts = iEntrustService.getReportDetail(entrustId);
if (rts == null) {
if (rts == null){
return;
}
Map<String, Object> beanParams = new HashMap<>(10);
......@@ -108,6 +107,7 @@ public class ReportController {
//六元素导出
List<SixElementReport> list = iEntrustService.getSampleSixElementCheck(entrustId);
list.forEach(this::initMapStr2AlongPro);
List<SixElementReport> al2o3AndTio2List = list.stream()
.filter(arg -> !"-".equals(arg.getAl2o3AndTio2()))
......@@ -121,7 +121,7 @@ public class ReportController {
//化学工业导出
List<IndustrialReport> list1 = iEntrustService.getSampleIndustrialCheck(entrustId);
list1.forEach(this::initMapStr2AlongPro);
beanParams.put("list3", list1);
beanParams.put("list3",list1);
WordUtil.writeWordReport(rts.getProjectName() + "(报告)", "report.ftl",
beanParams, response, FileExt.EXCL);
......@@ -136,7 +136,7 @@ public class ReportController {
*/
private void initMapStr2AlongPro(SixElementReport sixElement) {
String countResult = sixElement.getCountResult();
String countResult = sixElement.getCountResults();
HashMap<String, String> countResultMap = JSON.parseObject(countResult, HashMap.class);
sixElement.setAl2o3("-");
......@@ -159,16 +159,16 @@ public class ReportController {
sixElement.setSo3(countResultMap.getOrDefault(SixElementKey.SO3.getKey(), "0"));
}
private void initMapStr2AlongPro(IndustrialReport industrialReport) {
String countResult = industrialReport.getCountResult();
private void initMapStr2AlongPro(IndustrialReport industrialReport){
String countResult = industrialReport.getCountResults();
HashMap<String, String> countResultMap = JSON.parseObject(countResult, HashMap.class);
industrialReport.setAad(countResultMap.getOrDefault(IndustrialElementKey.Aad.getKey(), "0"));
industrialReport.setJz(countResultMap.getOrDefault(IndustrialElementKey.JZ.getKey(), "0"));
industrialReport.setMad(countResultMap.getOrDefault(IndustrialElementKey.Mad.getKey(), "0"));
industrialReport.setMjkg(countResultMap.getOrDefault(IndustrialElementKey.QnetAdMJkg.getKey(), "0"));
industrialReport.setStad(countResultMap.getOrDefault(IndustrialElementKey.StAd.getKey(), "0"));
industrialReport.setVad(countResultMap.getOrDefault(IndustrialElementKey.Vad.getKey(), "0"));
industrialReport.setAad(countResultMap.getOrDefault(IndustrialElementKey.Aad.getKey(),"0"));
industrialReport.setJz(countResultMap.getOrDefault(IndustrialElementKey.JZ.getKey(),"0"));
industrialReport.setMad(countResultMap.getOrDefault(IndustrialElementKey.Mad.getKey(),"0"));
industrialReport.setMjkg(countResultMap.getOrDefault(IndustrialElementKey.QnetAdMJkg.getKey(),"0"));
industrialReport.setStad(countResultMap.getOrDefault(IndustrialElementKey.StAd.getKey(),"0"));
industrialReport.setVad(countResultMap.getOrDefault(IndustrialElementKey.Vad.getKey(),"0"));
}
......
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.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.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -13,7 +13,11 @@ import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
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 = "微信接口")
@RestController
......@@ -28,6 +32,10 @@ public class WeiXinController {
@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) {
......@@ -47,39 +55,74 @@ public class WeiXinController {
return BaseResponse.errorMsg("失败!");
}
@ApiOperation(value = "获取accessToken信息-小程序端")
@GetMapping("/getAccessToken")
public BaseResponse getAccessToken() {
@ApiOperation(value = "当前登录用户")
@GetMapping("/getLoginUser")
public BaseResponse getLoginUser() {
try {
String accessToken = weiXinService.getAccessToken();
return BaseResponse.okData(accessToken);
return weiXinService.getLoginUser();
} catch (Exception e) {
log.debug("获取accessToken信息-小程序端{}", e);
log.debug("当前登录用户{}", e);
}
return BaseResponse.errorMsg("失败!");
}
@ApiOperation(value = "获取accessToken信息-管理端")
@GetMapping("/getPCAccessToken")
public BaseResponse getPCAccessToken() {
@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 {
String accessToken = weiXinService.getPCAccessToken();
return BaseResponse.okData(accessToken);
} catch (Exception e) {
log.debug("获取accessToken信息-管理端{}", e);
md = MessageDigest.getInstance("SHA-1");
byte[] digest = md.digest(param.getBytes());
tmpStr = byteToStr(digest);
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return BaseResponse.errorMsg("失败!");
return BaseResponse.okData(StrUtil.swapCase(tmpStr));
}
@ApiOperation(value = "当前登录用户")
@GetMapping("/getLoginUser")
public BaseResponse getLoginUser() {
try {
return weiXinService.getLoginUser();
} catch (Exception e) {
log.debug("当前登录用户{}", e);
/**
* 将字节数组转换为十六进制字符串
*
* @param byteArray
* @return
*/
private static String byteToStr(byte[] byteArray) {
String strDigest = "";
for (int i = 0; i < byteArray.length; i++) {
strDigest += byteToHexStr(byteArray[i]);
}
return BaseResponse.errorMsg("失败!");
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 @@
<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
(SELECT check_id,sample_id FROM sample_check_team) sct
ON sct.check_id = sc.id
......@@ -14,12 +14,12 @@
(SELECT cement_code,sample_code,sample_form,`name` as sample_name,weight,id
FROM sample) s
ON s.id = sscct.sample_id AND entrust_id = #{entrustId}
WHERE count_result IS NOT NULL;
WHERE count_results IS NOT NULL;
</select>
<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
(SELECT check_id,sample_id FROM sample_check_team) sct
ON sct.check_id = sc.id
......@@ -29,7 +29,6 @@
(SELECT cement_code,sample_code,sample_form,`name` as sample_name,weight,id
FROM sample) s
ON s.id = sscct.sample_id AND entrust_id = #{entrustId}
WHERE count_result IS NOT NULL;
WHERE count_results IS NOT NULL;
</select>
</mapper>
package cn.wise.sc.cement.business.model;
import lombok.Data;
import java.io.Serializable;
/**
......@@ -42,7 +41,7 @@ public class IndustrialReport implements Serializable {
/**
* 校核数据
*/
private String countResult;
private String countResults;
//下面是工业特性得检测项
......
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;
}
}
......@@ -42,24 +42,24 @@ public class SixElementReport implements Serializable {
/**
* 校核数据
*/
private String countResult;
private String countResults;
//下面为六元素
private String loi = "";
private String sio2 = "";
private String fe2o3 = "";
private String cao = "";
private String mgo = "";
private String so3 = "";
private String cl = "";
private String loi ="";
private String sio2 ="";
private String fe2o3 ="";
private String cao ="";
private String mgo ="";
private String so3 ="";
private String cl="";
//情况一:Al2O3(含TiO3)
private String al2o3AndTio2 = "";
private String al2o3AndTio2 ="";
//情况二:Al2O3和TiO3单独分开
private String al2o3 = "";
private String tio2 = "";
private String al2o3 ="";
private String tio2 ="";
}
......@@ -85,22 +85,20 @@ public interface INormProductionService extends IService<NormProduction> {
* @param end 结束时间
* @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 end 结束时间
* @param name 人员名字
* @param groupId 部门id
* @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 startTime 开始时间
* @param endTime 结束时间
......@@ -110,20 +108,18 @@ public interface INormProductionService extends IService<NormProduction> {
/**
* 导出产值总统计列表
*
* @param name 名字检索
* @param startTime 开始时间
* @param endTime 结束时间
* @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 endTime 结束时间
* @return 统计对象
*/
List<WorkloadStatisticsVo> workloadStatistics(Date startTime, Date endTime);
List<WorkloadStatisticsVo> workloadStatistics(Date startTime, Date endTime,Integer userId);
}
......@@ -391,6 +391,7 @@ public class NormProductionServiceImpl extends ServiceImpl<NormProductionMapper,
@Override
public List<ProductionVo> production(String name, Long start, Long end, Integer groupId) {
Date startDate = null;
Date endDate = new Date();
if (start != null && start != 0) {
......@@ -476,6 +477,7 @@ public class NormProductionServiceImpl extends ServiceImpl<NormProductionMapper,
return rts;
}
@Override
public void exportNormProductionStatistics(Long start, Long end, String name, Integer groupId, HttpServletResponse response) {
BaseResponse<List<NormProductionStatistics>> listBaseResponse = normProductionStatistics(start, end, name, groupId);
......@@ -590,7 +592,7 @@ public class NormProductionServiceImpl extends ServiceImpl<NormProductionMapper,
}
@Override
public List<WorkloadStatisticsVo> workloadStatistics(Date startTime, Date endTime) {
public List<WorkloadStatisticsVo> workloadStatistics(Date startTime, Date endTime, Integer userId) {
long start = getDefaultStart(startTime == null ? 0 : startTime.getTime());
long end = getDefaultEnd(endTime.getTime());
......@@ -601,15 +603,20 @@ public class NormProductionServiceImpl extends ServiceImpl<NormProductionMapper,
if (startTime != null) {
qw.ge("finish_time", DateUtil.format(DateUtil.date(start), "yyyy-MM-dd"));
}
if (userId != null && userId != 0) {
qw.eq("user_id", userId);
}
qw.le("finish_time", DateUtil.format(DateUtil.date(end), "yyyy-MM-dd"));
qw.eq("status", 2);
List<SampleDistribution> sampleDistributions = iSampleDistributionService.list(qw);
//脾气比能力大 蠢货
QueryWrapper<NonStandardApply> qwA = new QueryWrapper<>();
if (startTime != null) {
qwA.ge("start_time", DateUtil.format(DateUtil.date(start), "yyyy-MM-dd"));
}
if (userId != null && userId != 0) {
qwA.eq("user_id", userId);
}
qwA.le("start_time", DateUtil.format(DateUtil.date(end), "yyyy-MM-dd"));
qwA.eq("status", 2);
List<NonStandardApply> nonStandardApplies = iNonStandardApplyService.list(qwA);
......
......@@ -13,7 +13,6 @@ import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.Date;
......@@ -78,7 +77,6 @@ public class QualityApplyServiceImpl extends ServiceImpl<QualityApplyMapper, Qua
List<QualityApply> list = this.list(qw);
//找到所有项目id归类
Set<Integer> projectIds = list.stream().map(QualityApply::getProjectId).collect(Collectors.toSet());
String[] headers = null;
List<Object[]> datas = new ArrayList<>();
//关联部门名字
Set<Integer> userIds = list.stream()
......@@ -125,8 +123,8 @@ public class QualityApplyServiceImpl extends ServiceImpl<QualityApplyMapper, Qua
&& arg.getProjectId().intValue() == projectId)
.collect(Collectors.toList());
//以样品归类
Set<Integer> sampleIds = samples.stream().map(QualityApply::getTeamGroupId)
.collect(Collectors.toSet());
// Set<Integer> sampleIds = samples.stream().map(QualityApply::getTeamGroupId)
// .collect(Collectors.toSet());
//写每个样品的表头
list.stream()
......@@ -168,10 +166,10 @@ public class QualityApplyServiceImpl extends ServiceImpl<QualityApplyMapper, Qua
objs[7] = arg.getUserName();
for (int i = 0; i < inputValus.size(); i++) {
String value = inputValus.get(i);
if (value == null) {
if (value == null){
value = "0";
}
if (value.contains("\"")) {
if ( value.contains("\"")) {
value = value.replace("\"", "");
}
objs[8 + i] = value;
......@@ -182,7 +180,7 @@ public class QualityApplyServiceImpl extends ServiceImpl<QualityApplyMapper, Qua
}
}
ExcelUtil.excelExport("qualityApply", headers, datas, response);
ExcelUtil.excelExport("qualityApply", null, datas, response);
}
}
......@@ -36,6 +36,9 @@ public class WeiXinService {
@Autowired
RedisUtil redisUtil;
final static String ACCESS_TOKEN = "ACCESS_TOKEN";
final static String JSAPITICKET = "JSAPITICKET";
/**
* 获取登录token
*
......@@ -107,6 +110,37 @@ public class WeiXinService {
}
}
//获取accessToken信息
public String getJsapiTicket() {
try {
String accessToken;
String jsapiTicket;
if (!redisUtil.existsKey(ACCESS_TOKEN)) {
String param = "corpid=%s&corpsecret=%s";
param = String.format(param, corpid, corpsecret);
JSONObject jsonObject = WeixinInterfaceUtil.doGet(Global.ACCESSTOKENURL, param);
accessToken = jsonObject.getString("access_token");
redisUtil.setString(ACCESS_TOKEN, accessToken, 7200);
}
accessToken = redisUtil.getString(ACCESS_TOKEN) + "";
System.out.println("==================accessToken===================");
System.out.println(accessToken);
if (!redisUtil.existsKey(JSAPITICKET)) {
String param3 = "access_token=%s&type=agent_config";
param3 = String.format(param3, accessToken);
JSONObject ticketJsonObject = WeixinInterfaceUtil.doGet(Global.userTicket, param3);
jsapiTicket = ticketJsonObject.getString("ticket");
redisUtil.setString(JSAPITICKET, jsapiTicket, 7200);
}
jsapiTicket = redisUtil.getString(JSAPITICKET) + "";
return jsapiTicket;
} catch (Exception e) {
return null;
}
}
public String getPCAccessToken() {
try {
String param = "corpid=%s&corpsecret=%s";
......@@ -121,6 +155,7 @@ public class WeiXinService {
}
}
//获取用户信息
public JSONObject getUser(String accessToken, String userId) {
try {
......@@ -145,4 +180,5 @@ public class WeiXinService {
return BaseResponse.okData(loginUser);
}
}
......@@ -4,7 +4,6 @@ import org.apache.commons.io.FilenameUtils;
import org.csource.common.MyException;
import org.csource.common.NameValuePair;
import org.csource.fastdfs.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
......
......@@ -3,10 +3,9 @@ package cn.wise.sc.cement.business.util.weixin;
/**
* 功能说明:企业微信全局接口地址
* 修改说明:
*
* @author zhenglibing
* @version 0.1
* @date 2018年1月8日 下午2:27:43
* @version 0.1
*/
public interface Global {
......@@ -17,16 +16,29 @@ public interface Global {
*/
public static final String ACCESSTOKENURL = "https://qyapi.weixin.qq.com/cgi-bin/gettoken";
/**
* 微信公众平台,获取访问用户身份的接口地址,Https请求方式:GET
* 接口地址示例: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";
/**
* 微信公众平台,获取访问用户信息的接口地址,Https请求方式:GET
* 接口地址示例: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 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;
import cn.wise.sc.cement.business.model.ResultVO;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.*;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;
import java.util.*;
/**
* 艺哚哚对外开放接口 工具类
* 对外开放接口 工具类
*/
public class WeixinInterfaceUtil {
private static final String HOST = "https://ydd.whlyj.sh.gov.cn/"; //服务器IP与端口
private static final String APPID = "DSACTSYS";
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();
public static void main(String[] args) {
public static void main(String[] args){
String param = "corpid=%s&corpsecret=%s";
param = String.format(param, "ww348f91b2573c1867", "gFa_7XvXtCaoeAYERzjRwwz_OTJkJfgBb8weOKjmI3o");
try {
......@@ -30,19 +37,40 @@ public class WeixinInterfaceUtil {
e.printStackTrace();
}
}
public static JSONObject doGet(String url, String param) {
String path = url + "?" + param;
String path= url+"?"+ param;
RestTemplate restTemplate = new RestTemplate();
JSONObject resultMap = restTemplate.getForObject(path, JSONObject.class);
JSONObject resultMap = restTemplate.getForObject(path,JSONObject.class);
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里,
* 按照字母请求参数名的字母升序排列非空请求参数(包含 appid)
*
* @param sortedParams
* @return
*/
......@@ -68,4 +96,6 @@ public class WeixinInterfaceUtil {
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