修改了分页查询订单接口
This commit is contained in:
parent
f8345cd3e8
commit
6f7e297005
|
@ -2,16 +2,19 @@ package com.cultural.heritage.controller.wx;
|
|||
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.cultural.heritage.common.BaseResponse;
|
||||
import com.cultural.heritage.common.ErrorCode;
|
||||
import com.cultural.heritage.common.ResultUtils;
|
||||
import com.cultural.heritage.exception.BusinessException;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.junit.Test;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.HttpURLConnection;
|
||||
import java.net.MalformedURLException;
|
||||
import java.net.ProtocolException;
|
||||
import java.net.URL;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -23,11 +26,29 @@ import java.util.Map;
|
|||
@Tag(name = "小程序获取公众号文章")
|
||||
public class WeChatController {
|
||||
|
||||
private String getToken() throws MalformedURLException, IOException, ProtocolException {
|
||||
|
||||
@PostMapping("/getArticle")
|
||||
public BaseResponse<Object> getArticleInfo() {
|
||||
String result1 = null;
|
||||
try {
|
||||
result1 = getToken();
|
||||
Map<String,Object> token = JSON.parseObject(result1);
|
||||
String result2 = getContentList(token.get("access_token").toString());
|
||||
JSONObject jsonObject = JSON.parseObject(result2);
|
||||
System.out.println(jsonObject);
|
||||
return ResultUtils.success(jsonObject);
|
||||
} catch (IOException e) {
|
||||
log.info("获取公众号文章信息错误");
|
||||
throw new BusinessException(ErrorCode.SYSTEM_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private String getToken() throws IOException {
|
||||
// access_token接口https请求方式: GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
|
||||
String path = " https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential";
|
||||
String appid = "wx3f968a09e31d6bed";
|
||||
String secret = "847bdda7c2b01e88d59948b9ba50ef8d";
|
||||
String appid = "wx5d04ca2de0e628a8";
|
||||
String secret = "495af5bc4df1b86ffcfc21bb12daea76";
|
||||
URL url = new URL(path+"&appid=" + appid + "&secret=" + secret);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("GET");
|
||||
|
@ -41,14 +62,48 @@ public class WeChatController {
|
|||
sb.append(new String(b,0,len));
|
||||
}
|
||||
|
||||
System.out.println(sb.toString());
|
||||
System.out.println(sb);
|
||||
in.close();
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
// l2Xqw8jS3iBL3__mZ33T8TFMj_w2tnERt6rLLUAfwRP5OWzAj5BzJyhsmuMzo3GJ
|
||||
|
||||
// private String getOneContent(String token) throws IOException {
|
||||
// String path = " https://api.weixin.qq.com/cgi-bin/freepublish/getarticle?access_token=" + token;
|
||||
// URL url = new URL(path);
|
||||
// HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
// connection.setRequestMethod("POST");
|
||||
// connection.setDoOutput(true);
|
||||
// connection.setRequestProperty("content-type", "application/json;charset=utf-8");
|
||||
// connection.connect();
|
||||
// // post发送的参数
|
||||
// Map<String, Object> map = new HashMap<>();
|
||||
// map.put("article_id", "l2Xqw8jS3iBL3__mZ33T8TFMj_w2tnERt6rLLUAfwRP5OWzAj5BzJyhsmuMzo3GJ"); // news表示图文类型的素材,具体看API文档
|
||||
// // 将map转换成json字符串
|
||||
// String paramBody = JSON.toJSONString(map); // 这里用了Alibaba的fastjson
|
||||
//
|
||||
// OutputStream out = connection.getOutputStream();
|
||||
// BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(out));
|
||||
// bw.write(paramBody); // 向流中写入参数字符串
|
||||
// bw.flush();
|
||||
//
|
||||
// InputStream in = connection.getInputStream();
|
||||
// byte[] b = new byte[100];
|
||||
// int len = -1;
|
||||
// StringBuffer sb = new StringBuffer();
|
||||
// while((len = in.read(b)) != -1) {
|
||||
// sb.append(new String(b,0,len));
|
||||
// }
|
||||
//
|
||||
// in.close();
|
||||
// return sb.toString();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
private String getContentList(String token) throws IOException {
|
||||
String path = " https://api.weixin.qq.com/cgi-bin/material/batchget_material?access_token=" + token;
|
||||
String path = " https://api.weixin.qq.com/cgi-bin/freepublish/batchget?access_token=" + token;
|
||||
URL url = new URL(path);
|
||||
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
|
||||
connection.setRequestMethod("POST");
|
||||
|
@ -57,9 +112,9 @@ public class WeChatController {
|
|||
connection.connect();
|
||||
// post发送的参数
|
||||
Map<String, Object> map = new HashMap<>();
|
||||
map.put("type", "news"); // news表示图文类型的素材,具体看API文档
|
||||
map.put("offset", 0);
|
||||
map.put("count", 1);
|
||||
map.put("offset", 0); // news表示图文类型的素材,具体看API文档
|
||||
map.put("count", 20);
|
||||
map.put("no_content", 1);
|
||||
// 将map转换成json字符串
|
||||
String paramBody = JSON.toJSONString(map); // 这里用了Alibaba的fastjson
|
||||
|
||||
|
@ -81,14 +136,13 @@ public class WeChatController {
|
|||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test() throws IOException {
|
||||
|
||||
String result1 = getToken();
|
||||
Map<String,Object> token = (Map<String, Object>) JSON.parseObject(result1);
|
||||
String result2 = getContentList(token.get("access_token").toString());
|
||||
System.out.println(result2);
|
||||
}
|
||||
// @Test
|
||||
// public void test() throws IOException {
|
||||
// String result1 = getToken();
|
||||
// Map<String,Object> token = (Map<String, Object>) JSON.parseObject(result1);
|
||||
// String result2 = getContentList(token.get("access_token").toString());
|
||||
// System.out.println(result2);
|
||||
// }
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.cultural.heritage.service.address.impl;
|
|||
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
||||
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||
import com.cultural.heritage.common.ErrorCode;
|
||||
import com.cultural.heritage.exception.BusinessException;
|
||||
import com.cultural.heritage.exception.ThrowUtils;
|
||||
import com.cultural.heritage.mapper.AddressMapper;
|
||||
import com.cultural.heritage.model.entity.Address;
|
||||
|
@ -20,6 +19,9 @@ public class AddressServiceImpl extends ServiceImpl<AddressMapper, Address> impl
|
|||
Integer isDefault = address.getIsDefault();
|
||||
Long userId = address.getUserId();
|
||||
List<Address> list = this.getUserAddressById(userId);
|
||||
if (list.size() == 0) {
|
||||
return ;
|
||||
}
|
||||
if (isDefault == 1) {
|
||||
list.forEach(item -> item.setIsDefault(0));
|
||||
}
|
||||
|
|
|
@ -52,3 +52,6 @@ wx:
|
|||
mini:
|
||||
appId: wx3f968a09e31d6bed
|
||||
appSecret: 847bdda7c2b01e88d59948b9ba50ef8d
|
||||
official:
|
||||
appId: wx5d04ca2de0e628a8
|
||||
appSecret: 495af5bc4df1b86ffcfc21bb12daea76
|
Loading…
Reference in New Issue
Block a user