| | |
| | | @ApiImplicitParam(name = "query", value = "传递的参数,小程序端在APP.onLaunch直接获取参数", dataType = "String", paramType = "query"), |
| | | }) |
| | | public Object generate_urllink(String path, String query) { |
| | | String access_token = PayUtils.getAccessToken(); |
| | | JSONObject responseBody = null; |
| | | try { |
| | | String access_token = PayUtils.getAccessToken(); |
| | | |
| | | String url = "https://api.weixin.qq.com/wxa/generate_urllink?access_token=" + access_token; |
| | | String url = "https://api.weixin.qq.com/wxa/generate_urllink?access_token=" + access_token; |
| | | |
| | | // 设置请求报头 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | // 设置请求报头 |
| | | HttpHeaders headers = new HttpHeaders(); |
| | | headers.setContentType(MediaType.APPLICATION_JSON); |
| | | |
| | | // 创建请求主体 |
| | | Map<String, Object> requestBody = new HashMap<>(); |
| | | if (StrUtil.isNotBlank(path)) { |
| | | requestBody.put("path", path); |
| | | // 创建请求主体 |
| | | Map<String, Object> requestBody = new HashMap<>(); |
| | | if (StrUtil.isNotBlank(path)) { |
| | | requestBody.put("path", path); |
| | | } |
| | | if (StrUtil.isNotBlank(query)) { |
| | | requestBody.put("query", query); |
| | | } |
| | | // 到期失效的 URL Link 失效类型,失效时间:0,失效间隔天数:1 |
| | | requestBody.put("expire_type", 1); |
| | | // 到期失效的 URL Link 的失效间隔天数,最长间隔天数为30天. expire_type为 1 时必填 |
| | | requestBody.put("expire_interval", 30); |
| | | |
| | | // 用请求体和头创建HttpEntity对象 |
| | | HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers); |
| | | |
| | | // 发送POST请求并获得响应 |
| | | ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity( |
| | | url, |
| | | requestEntity, |
| | | JSONObject.class |
| | | ); |
| | | |
| | | // 获取响应体 |
| | | responseBody = responseEntity.getBody(); |
| | | } catch (Exception e) { |
| | | log.error("generate_urllink异常",e); |
| | | } |
| | | if (StrUtil.isNotBlank(query)) { |
| | | requestBody.put("query", query); |
| | | } |
| | | // 到期失效的 URL Link 失效类型,失效时间:0,失效间隔天数:1 |
| | | requestBody.put("expire_type", 1); |
| | | // 到期失效的 URL Link 的失效间隔天数,最长间隔天数为30天. expire_type为 1 时必填 |
| | | requestBody.put("expire_interval", 30); |
| | | |
| | | // 用请求体和头创建HttpEntity对象 |
| | | HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestBody, headers); |
| | | |
| | | // 发送POST请求并获得响应 |
| | | ResponseEntity<JSONObject> responseEntity = restTemplate.postForEntity( |
| | | url, |
| | | requestEntity, |
| | | JSONObject.class |
| | | ); |
| | | |
| | | // 获取响应体 |
| | | JSONObject responseBody = responseEntity.getBody(); |
| | | |
| | | // 打印响应体 |
| | | System.out.println(responseBody); |
| | | log.info("响应体---->{}",responseBody); |
| | | |
| | | return responseBody; |
| | | } |