登陆集成微信小程序登陆及其增加余额支付功能等
This commit is contained in:
1 parent
1d4d2b2573
commit
2c4b1ceaa2
5 files changed
+121
-39
No files matched your search
@@ -0,0 +1,28 @@
|
|||||||
|
package com.ruoyi.app.common.utils;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonInclude.Include;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author <a href="https://github.com/binarywang">Binary Wang</a>
|
||||||
|
*/
|
||||||
|
public class JsonUtils {
|
||||||
|
private static final ObjectMapper JSON = new ObjectMapper();
|
||||||
|
|
||||||
|
static {
|
||||||
|
JSON.setSerializationInclusion(Include.NON_NULL);
|
||||||
|
JSON.configure(SerializationFeature.INDENT_OUTPUT, Boolean.TRUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toJson(Object obj) {
|
||||||
|
try {
|
||||||
|
return JSON.writeValueAsString(obj);
|
||||||
|
} catch (JsonProcessingException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,22 +1,33 @@
|
|||||||
package com.ruoyi.app.modular.auth.controller;
|
package com.ruoyi.app.modular.auth.controller;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
import cn.binarywang.wx.miniapp.api.WxMaService;
|
||||||
|
import cn.binarywang.wx.miniapp.bean.WxMaJscode2SessionResult;
|
||||||
|
import cn.binarywang.wx.miniapp.bean.WxMaUserInfo;
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.itmuch.lightsecurity.annotation.PreAuthorize;
|
import com.itmuch.lightsecurity.annotation.PreAuthorize;
|
||||||
import com.itmuch.lightsecurity.jwt.JwtOperator;
|
import com.itmuch.lightsecurity.jwt.JwtOperator;
|
||||||
import com.itmuch.lightsecurity.jwt.User;
|
import com.itmuch.lightsecurity.jwt.User;
|
||||||
import com.itmuch.lightsecurity.jwt.UserOperator;
|
import com.itmuch.lightsecurity.jwt.UserOperator;
|
||||||
import com.ruoyi.app.common.R;
|
import com.ruoyi.app.common.R;
|
||||||
import com.ruoyi.app.common.persistence.model.StoreMember;
|
import com.ruoyi.app.common.persistence.model.StoreMember;
|
||||||
|
import com.ruoyi.app.common.utils.JsonUtils;
|
||||||
import com.ruoyi.app.modular.member.service.IMemberService;
|
import com.ruoyi.app.modular.member.service.IMemberService;
|
||||||
import com.ruoyi.app.modular.member.service.vo.LoginVO;
|
import com.ruoyi.app.modular.member.service.vo.LoginVO;
|
||||||
|
|
||||||
import io.swagger.annotations.Api;
|
import io.swagger.annotations.Api;
|
||||||
import io.swagger.annotations.ApiOperation;
|
import io.swagger.annotations.ApiOperation;
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import me.chanjar.weixin.common.error.WxErrorException;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.validation.annotation.Validated;
|
import org.springframework.validation.annotation.Validated;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -25,6 +36,7 @@ import java.util.HashMap;
|
|||||||
* @Date 2019/6/27
|
* @Date 2019/6/27
|
||||||
**/
|
**/
|
||||||
//@RequestMapping(value = "/")
|
//@RequestMapping(value = "/")
|
||||||
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
|
||||||
@Api(value = "认证授权模块", tags = "认证授权模块", description = "认证授权模块")
|
@Api(value = "认证授权模块", tags = "认证授权模块", description = "认证授权模块")
|
||||||
@@ -32,6 +44,7 @@ public class AuthController {
|
|||||||
private final UserOperator userOperator;
|
private final UserOperator userOperator;
|
||||||
private final JwtOperator operator;
|
private final JwtOperator operator;
|
||||||
private final IMemberService memberService;
|
private final IMemberService memberService;
|
||||||
|
private final WxMaService wxService;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 获取当前登录用户信息
|
* 获取当前登录用户信息
|
||||||
@@ -53,25 +66,59 @@ public class AuthController {
|
|||||||
@PostMapping("/oauth/access_token")
|
@PostMapping("/oauth/access_token")
|
||||||
@ApiOperation(value = "获取token",notes = "获取token")
|
@ApiOperation(value = "获取token",notes = "获取token")
|
||||||
public R loginReturnToken(@Validated @RequestBody LoginVO loginVO) {
|
public R loginReturnToken(@Validated @RequestBody LoginVO loginVO) {
|
||||||
Boolean isProduct = false;
|
Boolean isProduct = true; //true 开启真实小程序环境
|
||||||
String openid = null;
|
String openid = "orIMY4xGhMmipwFZoSL1vOhUNFZ0";
|
||||||
if(isProduct){
|
WxMaUserInfo userInfo = null;
|
||||||
//todo 此处结合小程序API
|
try{
|
||||||
}else{
|
if(isProduct){
|
||||||
openid = "orIMY4xGhMmipwFZoSL1vOhUNFZ0";
|
WxMaJscode2SessionResult session = wxService.getUserService()
|
||||||
|
.getSessionInfo(loginVO.getCode());
|
||||||
|
//log.info(session.getSessionKey());
|
||||||
|
//log.info(session.getOpenid());
|
||||||
|
//TODO 可以增加自己的逻辑,关联业务相关数据
|
||||||
|
|
||||||
|
String sessionKey = session.getSessionKey();
|
||||||
|
openid = session.getOpenid();
|
||||||
|
// 解密用户信息
|
||||||
|
userInfo = wxService.getUserService()
|
||||||
|
.getUserInfo(sessionKey, loginVO.getEncrypted_data(), loginVO.getIv());
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
StoreMember member = memberService.login(openid);
|
||||||
|
//System.out.println(member);
|
||||||
|
User user = null;
|
||||||
|
if(member == null){
|
||||||
|
//新用户插入数据
|
||||||
|
StoreMember newMember = new StoreMember();
|
||||||
|
newMember.setOpenid(userInfo.getOpenId());
|
||||||
|
newMember.setNickname(userInfo.getNickName());
|
||||||
|
newMember.setHeadimg(userInfo.getAvatarUrl());
|
||||||
|
newMember.setSex(userInfo.getGender());
|
||||||
|
newMember.setCreateTime(new Date());
|
||||||
|
memberService.save(newMember);
|
||||||
|
user = User.builder()
|
||||||
|
.id(newMember.getId().intValue())
|
||||||
|
.username(newMember.getNickname())
|
||||||
|
.build();
|
||||||
|
}else{
|
||||||
|
user = User.builder()
|
||||||
|
.id(member.getId().intValue())
|
||||||
|
.username(member.getNickname())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
String token = operator.generateToken(user);
|
||||||
|
HashMap<String,String> map = new HashMap<>();
|
||||||
|
map.put("access_token",token);
|
||||||
|
return R.success(map);
|
||||||
|
} catch (WxErrorException e) {
|
||||||
|
//System.out.println(e.getMessage());
|
||||||
|
log.error(e.getMessage());
|
||||||
|
return R.error(4000,e.getMessage());
|
||||||
}
|
}
|
||||||
StoreMember member = memberService.login(openid);
|
|
||||||
if(member == null){
|
|
||||||
R.error(401,"用户登陆失败");
|
|
||||||
}
|
|
||||||
User user = User.builder()
|
|
||||||
.id(member.getId().intValue())
|
|
||||||
.username(member.getNickname())
|
|
||||||
//.roles(Arrays.asList("user", "admin"))
|
|
||||||
.build();
|
|
||||||
String token = operator.generateToken(user);
|
|
||||||
HashMap<String,String> map = new HashMap<>();
|
|
||||||
map.put("access_token",token);
|
|
||||||
return R.success(map);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -174,7 +174,7 @@ public class MallController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
HashMap<String,String> map = new HashMap<>();
|
HashMap<String,String> map = new HashMap<>();
|
||||||
map.put("orderSn",orderSn);
|
map.put("order_no",orderSn);
|
||||||
return R.success(map);
|
return R.success(map);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -87,23 +87,24 @@ public class PayController {
|
|||||||
orderService.payYue(storeOrder);
|
orderService.payYue(storeOrder);
|
||||||
return R.success("余额支付成功");
|
return R.success("余额支付成功");
|
||||||
}else{
|
}else{
|
||||||
|
return R.error(4000,"微信支付开发中");
|
||||||
//todo 微信支付
|
//todo 微信支付
|
||||||
try {
|
// try {
|
||||||
//WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
// //WxPayUnifiedOrderRequest orderRequest = new WxPayUnifiedOrderRequest();
|
||||||
orderRequest.setBody("主题");
|
// orderRequest.setBody("主题");
|
||||||
orderRequest.setOutTradeNo("订单号");
|
// orderRequest.setOutTradeNo("订单号");
|
||||||
orderRequest.setTotalFee(1);//元转成分
|
// orderRequest.setTotalFee(1);//元转成分
|
||||||
orderRequest.setOpenid("openId");
|
// orderRequest.setOpenid("openId");
|
||||||
orderRequest.setSpbillCreateIp("userIp");
|
// orderRequest.setSpbillCreateIp("userIp");
|
||||||
//orderRequest.setTimeStart("yyyyMMddHHmmss");
|
// //orderRequest.setTimeStart("yyyyMMddHHmmss");
|
||||||
// orderRequest.setTimeExpire("yyyyMMddHHmmss");
|
// // orderRequest.setTimeExpire("yyyyMMddHHmmss");
|
||||||
|
//
|
||||||
return R.success(wxPayService.createOrder(orderRequest));
|
// return R.success(wxPayService.createOrder(orderRequest));
|
||||||
} catch (Exception e) {
|
// } catch (Exception e) {
|
||||||
log.error("微信支付失败!订单号:{},原因:{}", orderNo, e.getMessage());
|
// log.error("微信支付失败!订单号:{},原因:{}", orderNo, e.getMessage());
|
||||||
e.printStackTrace();
|
// e.printStackTrace();
|
||||||
return R.error(4000,"支付失败,请稍后重试!");
|
// return R.error(4000,"支付失败,请稍后重试!");
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -58,9 +58,9 @@ spring:
|
|||||||
#driver-class-name: com.mysql.jdbc.Driver
|
#driver-class-name: com.mysql.jdbc.Driver
|
||||||
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
|
driver-class-name: com.p6spy.engine.spy.P6SpyDriver
|
||||||
#driverClassName: com.mysql.cj.jdbc.Driver
|
#driverClassName: com.mysql.cj.jdbc.Driver
|
||||||
username: supply
|
username: root
|
||||||
password: supply#@147
|
password: root
|
||||||
url: jdbc:p6spy:mysql://localhost:3306/supply?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=UTC
|
url: jdbc:p6spy:mysql://localhost:3306/ruoyi?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=UTC
|
||||||
#url: jdbc:mysql://localhost:3306/ruoyi?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=UTC
|
#url: jdbc:mysql://localhost:3306/ruoyi?autoReconnect=true&useUnicode=true&characterEncoding=utf8&zeroDateTimeBehavior=CONVERT_TO_NULL&useSSL=false&serverTimezone=UTC
|
||||||
type: com.alibaba.druid.pool.DruidDataSource #这里是配置druid连接池,以下都是druid的配置信息
|
type: com.alibaba.druid.pool.DruidDataSource #这里是配置druid连接池,以下都是druid的配置信息
|
||||||
druid:
|
druid:
|
||||||
@@ -149,3 +149,9 @@ wx:
|
|||||||
subAppId:
|
subAppId:
|
||||||
subMchId:
|
subMchId:
|
||||||
keyPath:
|
keyPath:
|
||||||
|
miniapp:
|
||||||
|
appid: wx604d2ea4702620d2
|
||||||
|
secret: 0beb4dad95fbd97cbaf2a0a4dec51575
|
||||||
|
token:
|
||||||
|
aesKey:
|
||||||
|
msgDataFormat: JSON
|
||||||
Reference in new issue
Block a user