master
parent
b5d6ba963b
commit
9cec82dc96
|
@ -0,0 +1,33 @@
|
||||||
|
package com.zxf.web.controller.wxapi;
|
||||||
|
|
||||||
|
|
||||||
|
import com.zxf.common.annotation.Anonymous;
|
||||||
|
import com.zxf.common.core.domain.AjaxResult;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
@CrossOrigin(origins = "*", maxAge = 3600) //允许前后端跨域,响应前的缓存持续1小时
|
||||||
|
@RequestMapping("wx")
|
||||||
|
@RestController
|
||||||
|
public class wxBusinessControllApi {
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(wxBusinessControllApi.class);
|
||||||
|
|
||||||
|
@Anonymous
|
||||||
|
@GetMapping("/getimage")
|
||||||
|
public AjaxResult getimage(@RequestParam Map param) {
|
||||||
|
log.info("获取首页轮播图图片地址 到时候返回静态服务器绝对路径");
|
||||||
|
List a = new ArrayList();
|
||||||
|
a.add("/images/1.jpg");
|
||||||
|
a.add("/images/2.jpg");
|
||||||
|
a.add("/images/3.jpg");
|
||||||
|
return AjaxResult.success(a);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,28 @@
|
||||||
|
package com.zxf.web.controller.wxapi;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson2.JSONObject;
|
||||||
|
import com.zxf.common.annotation.Anonymous;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import static com.zxf.common.utils.wx.HttpUtils.getOpenid;
|
||||||
|
@CrossOrigin(origins = "*", maxAge = 3600) //允许前后端跨域,响应前的缓存持续1小时
|
||||||
|
@RequestMapping("wxlogin")
|
||||||
|
@RestController
|
||||||
|
public class wxLoginControllApi {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
|
||||||
|
private static final Logger log = LoggerFactory.getLogger(wxLoginControllApi.class);
|
||||||
|
|
||||||
|
@Anonymous
|
||||||
|
@PostMapping("/getWxInfoTest")
|
||||||
|
public String getWxInfoTest(@RequestBody JSONObject obj) {
|
||||||
|
JSONObject wxJson = JSONObject.parseObject(getOpenid(obj.getString("code")));
|
||||||
|
log.info("微信的返回值{}", wxJson);
|
||||||
|
return wxJson.toJSONString();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -18,7 +18,7 @@ zxf:
|
||||||
# 开发环境配置
|
# 开发环境配置
|
||||||
server:
|
server:
|
||||||
# 服务器的HTTP端口,默认为8080
|
# 服务器的HTTP端口,默认为8080
|
||||||
port: 8089
|
port: 8080
|
||||||
servlet:
|
servlet:
|
||||||
# 应用的访问路径
|
# 应用的访问路径
|
||||||
context-path: /
|
context-path: /
|
||||||
|
@ -70,7 +70,8 @@ spring:
|
||||||
# redis 配置
|
# redis 配置
|
||||||
redis:
|
redis:
|
||||||
# 地址
|
# 地址
|
||||||
host: www.zxfltt.icu
|
# host: www.zxfltt.icu
|
||||||
|
host: 101.43.135.234
|
||||||
# 端口,默认为6379
|
# 端口,默认为6379
|
||||||
port: 6379
|
port: 6379
|
||||||
# 数据库索引
|
# 数据库索引
|
||||||
|
@ -136,3 +137,6 @@ flowable:
|
||||||
database-schema-update: false
|
database-schema-update: false
|
||||||
# 关闭定时任务JOB
|
# 关闭定时任务JOB
|
||||||
async-executor-activate: false
|
async-executor-activate: false
|
||||||
|
wx:
|
||||||
|
AppId: wx9726c3834fcb3bd1
|
||||||
|
AppSecret: 28ac26ddbef7722863b512380513d66f
|
|
@ -0,0 +1,85 @@
|
||||||
|
package com.zxf.common.utils.wx;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
|
||||||
|
public class HttpUtils {
|
||||||
|
public static String getRequest(String httpurl) {
|
||||||
|
|
||||||
|
HttpURLConnection connection = null;
|
||||||
|
InputStream is = null;
|
||||||
|
BufferedReader br = null;
|
||||||
|
String result = null;// 返回结果字符串
|
||||||
|
try {
|
||||||
|
// 创建远程url连接对象
|
||||||
|
URL url = new URL(httpurl);
|
||||||
|
// 通过远程url连接对象打开一个连接,强转成httpURLConnection类
|
||||||
|
connection = (HttpURLConnection) url.openConnection();
|
||||||
|
// 设置连接方式:get
|
||||||
|
connection.setRequestMethod("GET");
|
||||||
|
// 设置连接主机服务器的超时时间:15000毫秒
|
||||||
|
connection.setConnectTimeout(15000);
|
||||||
|
// 设置读取远程返回的数据时间:60000毫秒
|
||||||
|
connection.setReadTimeout(60000);
|
||||||
|
// 发送请求
|
||||||
|
connection.connect();
|
||||||
|
// 通过connection连接,获取输入流
|
||||||
|
if (connection.getResponseCode() == 200) {
|
||||||
|
is = connection.getInputStream();
|
||||||
|
// 封装输入流is,并指定字符集
|
||||||
|
br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||||
|
// 存放数据
|
||||||
|
StringBuffer sbf = new StringBuffer();
|
||||||
|
String temp = null;
|
||||||
|
while ((temp = br.readLine()) != null) {
|
||||||
|
sbf.append(temp);
|
||||||
|
sbf.append("\r\n");
|
||||||
|
}
|
||||||
|
result = sbf.toString();
|
||||||
|
}
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} finally {
|
||||||
|
// 关闭资源
|
||||||
|
if (null != br) {
|
||||||
|
try {
|
||||||
|
br.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (null != is) {
|
||||||
|
try {
|
||||||
|
is.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
connection.disconnect();// 关闭远程连接
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static String getOpenid(String code) {
|
||||||
|
// 调用接口必要的参数
|
||||||
|
StringBuilder data=new StringBuilder();
|
||||||
|
// appid、secret定义在配置文件中,注入到项目里
|
||||||
|
data.append("appid="+"wx9726c3834fcb3bd1"+"&");
|
||||||
|
data.append("secret="+"28ac26ddbef7722863b512380513d66f"+"&");
|
||||||
|
data.append("js_code="+code+"&");
|
||||||
|
data.append("grant_type="+ "authorization_code");
|
||||||
|
String response = HttpUtils.getRequest("https://api.weixin.qq.com/sns/jscode2session?" + data);
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -35,9 +35,9 @@ module.exports = {
|
||||||
proxy: {
|
proxy: {
|
||||||
// detail: https://cli.vuejs.org/config/#devserver-proxy
|
// detail: https://cli.vuejs.org/config/#devserver-proxy
|
||||||
[process.env.VUE_APP_BASE_API]: {
|
[process.env.VUE_APP_BASE_API]: {
|
||||||
// target: `http://localhost:8080`,
|
target: `http://localhost:8080`,
|
||||||
// target: `http://101.43.135.234:8080`,
|
//target: `http://101.43.135.234:8089`,
|
||||||
target: `http://113.125.119.22:9000`,
|
// target: `http://113.125.119.22:9000`,
|
||||||
changeOrigin: true,
|
changeOrigin: true,
|
||||||
pathRewrite: {
|
pathRewrite: {
|
||||||
['^' + process.env.VUE_APP_BASE_API]: ''
|
['^' + process.env.VUE_APP_BASE_API]: ''
|
||||||
|
|
Loading…
Reference in New Issue