| | |
| | | package com.stylefeng.guns.modular.system.util; |
| | | |
| | | import cn.hutool.http.HttpRequest; |
| | | import cn.hutool.http.HttpResponse; |
| | | import cn.hutool.http.HttpUtil; |
| | | import com.alibaba.fastjson.JSON; |
| | | import com.alibaba.fastjson.JSONObject; |
| | | import com.fasterxml.jackson.databind.ObjectMapper; |
| | |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | | @Autowired |
| | | private RedisUtil redisUtil; |
| | | |
| | | |
| | | |
| | |
| | | String url = "https://api.weixin.qq.com/sns/jscode2session?appid=" + wxAppletsAppid + "&secret=" + wxAppletsAppSecret |
| | | + "&js_code=" + jscode + "&grant_type=authorization_code"; |
| | | String forObject = restTemplate.getForObject(url, String.class); |
| | | System.err.println(forObject); |
| | | JSONObject jsonObject = JSON.parseObject(forObject); |
| | | int errcode = jsonObject.getIntValue("errcode"); |
| | | Map<String, String> map = new HashMap<>(); |
| | |
| | | String ticket = JSONObject.parseObject(backData).getString("ticket"); |
| | | return ticket; |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | public String getWxAppletsAccessToken(){ |
| | | String wxAppletsAccessToken = redisUtil.getValue("wxAppletsAccessToken"); |
| | | if(ToolUtil.isNotEmpty(wxAppletsAccessToken)){ |
| | | return wxAppletsAccessToken; |
| | | } |
| | | String appletsAccessToken = getAppletsAccessToken(); |
| | | redisUtil.setStrValue("wxAppletsAccessToken", appletsAccessToken, 7200); |
| | | return appletsAccessToken; |
| | | } |
| | | |
| | | /** |
| | | * 获取微信小程序token |
| | | * @return |
| | | */ |
| | | public String getAppletsAccessToken() { |
| | | String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + wxAppletsAppid + "&secret=" + wxAppletsAppSecret; |
| | | HttpRequest get = HttpUtil.createGet(url); |
| | | HttpResponse response = get.execute(); |
| | | if(response.getStatus() != 200){ |
| | | return ""; |
| | | } |
| | | JSONObject jsonObject = JSON.parseObject(response.body()); |
| | | return jsonObject.getString("access_token"); |
| | | } |
| | | |
| | | |
| | | |
| | | /*** |
| | | * 获取acess_token (公众号) |
| | |
| | | } |
| | | |
| | | public String getUrlLink(String path, String query) throws Exception{ |
| | | String wxAppletsAccessToken = getAccessToken(); |
| | | String wxAppletsAccessToken = getWxAppletsAccessToken(); |
| | | String url = "https://api.weixin.qq.com/wxa/generate_urllink?access_token=" + wxAppletsAccessToken; |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("expire_type", 1); |
| | |
| | | } |
| | | |
| | | public String getPhone(String code) throws Exception{ |
| | | String wxAppletsAccessToken = getAccessToken(); |
| | | String wxAppletsAccessToken = getWxAppletsAccessToken(); |
| | | String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token=" + wxAppletsAccessToken; |
| | | Map<String, Object> param = new HashMap<>(); |
| | | param.put("code",code); |
| | |
| | | |
| | | @Autowired |
| | | private UserInfoController userInfoController; |
| | | public String rid(String path, String query) throws Exception{ |
| | | public String rid(String path, Integer driverId) throws Exception{ |
| | | // 获取access_token |
| | | String accessToken = getAccessToken(); |
| | | String accessToken = getWxAppletsAccessToken(); |
| | | // 替换CREATE_CODE_URL |
| | | String url = "https://api.weixin.qq.com/cgi-bin/wxaapp/createwxaqrcode?access_token="+accessToken; |
| | | // 发送请求 |
| | | String stringApiResult = null; |
| | | try { |
| | | HashMap<String, String> map = new HashMap<>(); |
| | | map.put("path", path+"?driverId=979"); |
| | | map.put("path", path+"?driverId=" + driverId); |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | HttpEntity requestEntity = new HttpEntity(map, headers); |