mirror of
https://gitee.com/lab1024/smart-admin.git
synced 2025-10-03 02:36:39 +08:00
adding wx-pay and Authentication Interceptor logic.
This commit is contained in:
parent
4ff0f08304
commit
60ebc350d6
@ -91,13 +91,13 @@ public class SmartAuthenticationInterceptor extends HandlerInterceptorAdapter {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(!request.getServletPath().startsWith("/royalcanin")) {
|
||||||
//根据token获取登录用户
|
//根据token获取登录用户
|
||||||
RequestTokenBO requestToken = loginTokenService.getEmployeeTokenInfo(xAccessToken);
|
RequestTokenBO requestToken = loginTokenService.getEmployeeTokenInfo(xAccessToken);
|
||||||
if (null == requestToken &&!request.getServletPath().startsWith("/royalcanin")) {
|
if (null == requestToken) {
|
||||||
this.outputResult(response, LoginResponseCodeConst.LOGIN_ERROR);
|
this.outputResult(response, LoginResponseCodeConst.LOGIN_ERROR);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
//判断接口权限
|
//判断接口权限
|
||||||
String methodName = ((HandlerMethod) handler).getMethod().getName();
|
String methodName = ((HandlerMethod) handler).getMethod().getName();
|
||||||
String className = ((HandlerMethod) handler).getBeanType().getName();
|
String className = ((HandlerMethod) handler).getBeanType().getName();
|
||||||
@ -127,6 +127,14 @@ public class SmartAuthenticationInterceptor extends HandlerInterceptorAdapter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
SmartRequestTokenUtil.setUser(request, requestToken);
|
SmartRequestTokenUtil.setUser(request, requestToken);
|
||||||
|
}else {
|
||||||
|
//根据token获取登录用户
|
||||||
|
String requestToken = loginTokenService.getRoyalcaninTokenInfo(xAccessToken);
|
||||||
|
if (requestToken == null){
|
||||||
|
this.outputResult(response, LoginResponseCodeConst.LOGIN_ERROR);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
package net.lab1024.smartadmin.module.system.login;
|
package net.lab1024.smartadmin.module.system.login;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import net.lab1024.smartadmin.common.constant.JudgeEnum;
|
import net.lab1024.smartadmin.common.constant.JudgeEnum;
|
||||||
import net.lab1024.smartadmin.module.system.employee.EmployeeService;
|
import net.lab1024.smartadmin.module.system.employee.EmployeeService;
|
||||||
import net.lab1024.smartadmin.module.system.employee.constant.EmployeeStatusEnum;
|
import net.lab1024.smartadmin.module.system.employee.constant.EmployeeStatusEnum;
|
||||||
@ -10,6 +11,10 @@ import io.jsonwebtoken.Claims;
|
|||||||
import io.jsonwebtoken.Jwts;
|
import io.jsonwebtoken.Jwts;
|
||||||
import io.jsonwebtoken.SignatureAlgorithm;
|
import io.jsonwebtoken.SignatureAlgorithm;
|
||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import net.lab1024.smartadmin.module.system.royalcanin.MemberService;
|
||||||
|
import net.lab1024.smartadmin.module.system.royalcanin.member.MemberGetEntity;
|
||||||
|
import net.lab1024.smartadmin.util.MapRemoveNullUtil;
|
||||||
|
import net.lab1024.smartadmin.util.SmartHttpUtil;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.beans.factory.annotation.Value;
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
@ -33,6 +38,8 @@ import java.util.UUID;
|
|||||||
@Service
|
@Service
|
||||||
public class LoginTokenService {
|
public class LoginTokenService {
|
||||||
|
|
||||||
|
private String url = "http://miniapp-test.royalcanin.com.cn:7080/crm/member/";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 过期时间一天
|
* 过期时间一天
|
||||||
*/
|
*/
|
||||||
@ -49,6 +56,10 @@ public class LoginTokenService {
|
|||||||
private EmployeeService employeeService;
|
private EmployeeService employeeService;
|
||||||
|
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private MemberService memberService;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 功能描述: 生成JWT TOKEN
|
* 功能描述: 生成JWT TOKEN
|
||||||
*
|
*
|
||||||
@ -115,4 +126,26 @@ public class LoginTokenService {
|
|||||||
return new RequestTokenBO(employeeBO);
|
return new RequestTokenBO(employeeBO);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getRoyalcaninTokenInfo(String token) {
|
||||||
|
|
||||||
|
MemberGetEntity memberGetEntity =new MemberGetEntity();
|
||||||
|
String sb = "";
|
||||||
|
try {
|
||||||
|
Claims claims = Jwts.parser().setSigningKey(jwtKey).parseClaimsJws(token).getBody();
|
||||||
|
String userId = claims.get(CLAIM_ID_KEY).toString();
|
||||||
|
memberGetEntity.setChannelId(15);
|
||||||
|
memberGetEntity.setId(Integer.parseInt(userId));
|
||||||
|
sb = SmartHttpUtil.sendPostForm(url+"get", MapRemoveNullUtil.setConditionMap(memberGetEntity),null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("getEmployeeTokenInfo error:{}", e);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
JSONObject jsonObject = JSONObject.parseObject(sb);
|
||||||
|
JSONObject json = JSONObject.parseObject(jsonObject.getString("data"));
|
||||||
|
if(!jsonObject.getString("code").equals("0")) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return json.getString("id");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -49,7 +49,7 @@ public class MemberService {
|
|||||||
MapRemoveNullUtil.removeNullEntry(paramMap);
|
MapRemoveNullUtil.removeNullEntry(paramMap);
|
||||||
String sb = SmartHttpUtil.sendPostForm(url+"get",paramMap,null);
|
String sb = SmartHttpUtil.sendPostForm(url+"get",paramMap,null);
|
||||||
JSONObject jsonObject = JSONObject.parseObject(sb);
|
JSONObject jsonObject = JSONObject.parseObject(sb);
|
||||||
if(!jsonObject.getString("code").equals("-1")){
|
if(jsonObject.getString("code").equals("0")){
|
||||||
JSONObject json = JSONObject.parseObject(jsonObject.getString("data"));
|
JSONObject json = JSONObject.parseObject(jsonObject.getString("data"));
|
||||||
String id = json.getString("id");
|
String id = json.getString("id");
|
||||||
jsonObject.put("xaccessToken",generateToken(id));
|
jsonObject.put("xaccessToken",generateToken(id));
|
||||||
|
@ -6,11 +6,17 @@ import lombok.extern.slf4j.Slf4j;
|
|||||||
import net.lab1024.smartadmin.common.anno.OperateLog;
|
import net.lab1024.smartadmin.common.anno.OperateLog;
|
||||||
import net.lab1024.smartadmin.constant.SwaggerTagConst;
|
import net.lab1024.smartadmin.constant.SwaggerTagConst;
|
||||||
import net.lab1024.smartadmin.module.system.qrcode.QRCodeUtil;
|
import net.lab1024.smartadmin.module.system.qrcode.QRCodeUtil;
|
||||||
|
import net.lab1024.smartadmin.module.system.wxpay.wxPay.WxPayEntity;
|
||||||
|
import net.lab1024.smartadmin.util.MapRemoveNullUtil;
|
||||||
import org.springframework.web.bind.annotation.GetMapping;
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestBody;
|
||||||
import org.springframework.web.bind.annotation.RestController;
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.net.Inet4Address;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@ -24,7 +30,6 @@ public class WxpayController {
|
|||||||
|
|
||||||
@GetMapping("royalcanin/qrCode")
|
@GetMapping("royalcanin/qrCode")
|
||||||
public void getQRCode(String codeContent, HttpServletResponse response) {
|
public void getQRCode(String codeContent, HttpServletResponse response) {
|
||||||
System.out.println("codeContent=" + codeContent);
|
|
||||||
try {
|
try {
|
||||||
/*
|
/*
|
||||||
* 调用工具类生成二维码并输出到输出流中
|
* 调用工具类生成二维码并输出到输出流中
|
||||||
@ -38,38 +43,29 @@ public class WxpayController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@GetMapping("royalcanin/unifiedOrder")
|
@PostMapping("royalcanin/unifiedOrder")
|
||||||
public void unifiedOrder(String codeContent, HttpServletResponse response) throws Exception {
|
public void unifiedOrder(@RequestBody WxPayEntity wxPayEntity, HttpServletResponse response) throws Exception {
|
||||||
MyConfig config = new MyConfig();
|
MyConfig config = new MyConfig();
|
||||||
WXPay wxpay = new WXPay(config);
|
WXPay wxpay = new WXPay(config);
|
||||||
|
InetAddress ip4 = Inet4Address.getLocalHost();
|
||||||
Map<String, String> data = new HashMap<String, String>();
|
Map<String,String> data = MapRemoveNullUtil.setConditionMap(wxPayEntity);
|
||||||
data.put("body", "腾讯充值中心-QQ会员充值");
|
data.put("spbill_create_ip", ip4.getHostAddress());
|
||||||
data.put("out_trade_no", "2016090910595900000012");
|
|
||||||
data.put("device_info", "");
|
|
||||||
data.put("fee_type", "CNY");
|
|
||||||
data.put("total_fee", "1");
|
|
||||||
data.put("spbill_create_ip", "123.12.12.123");
|
|
||||||
data.put("notify_url", "http://www.example.com/wxpay/notify");
|
|
||||||
data.put("trade_type", "NATIVE"); // 此处指定为扫码支付
|
data.put("trade_type", "NATIVE"); // 此处指定为扫码支付
|
||||||
data.put("product_id", "12");
|
data.put("body","皇家宠物食品官方商城");
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Map<String, String> resp = wxpay.unifiedOrder(data);
|
Map<String, String> resp = wxpay.unifiedOrder(data);
|
||||||
QRCodeUtil.createCodeToOutputStream(resp.toString(), response.getOutputStream());
|
QRCodeUtil.createCodeToOutputStream(resp.get("code_url"), response.getOutputStream());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("royalcanin/orderQuery")
|
@PostMapping("royalcanin/orderQuery")
|
||||||
public String orderQuery(String codeContent, HttpServletResponse response) throws Exception {
|
public String orderQuery(@RequestBody WxPayEntity wxPayEntity, HttpServletResponse response) throws Exception {
|
||||||
MyConfig config = new MyConfig();
|
MyConfig config = new MyConfig();
|
||||||
WXPay wxpay = new WXPay(config);
|
WXPay wxpay = new WXPay(config);
|
||||||
|
|
||||||
Map<String, String> data = new HashMap<String, String>();
|
Map<String, String> data = MapRemoveNullUtil.setConditionMap(wxPayEntity);
|
||||||
data.put("out_trade_no", "2016090910595900000012");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Map<String, String> resp = wxpay.orderQuery(data);
|
Map<String, String> resp = wxpay.orderQuery(data);
|
||||||
return resp.toString();
|
return resp.toString();
|
||||||
@ -79,20 +75,18 @@ public class WxpayController {
|
|||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("royalcanin/refundQuery")
|
@PostMapping("royalcanin/refundQuery")
|
||||||
public void refundQuery(String codeContent, HttpServletResponse response) throws Exception {
|
public String refundQuery(@RequestBody WxPayEntity wxPayEntity, HttpServletResponse response) throws Exception {
|
||||||
MyConfig config = new MyConfig();
|
MyConfig config = new MyConfig();
|
||||||
WXPay wxpay = new WXPay(config);
|
WXPay wxpay = new WXPay(config);
|
||||||
|
Map<String, String> data = MapRemoveNullUtil.setConditionMap(wxPayEntity);
|
||||||
Map<String, String> data = new HashMap<String, String>();
|
|
||||||
data.put("out_trade_no", "2016090910595900000012");
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Map<String, String> resp = wxpay.refundQuery(data);
|
Map<String, String> resp = wxpay.refundQuery(data);
|
||||||
System.out.println(resp);
|
return resp.toString();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,27 @@
|
|||||||
|
package net.lab1024.smartadmin.module.system.wxpay.wxPay;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class WxPayEntity {
|
||||||
|
|
||||||
|
public String body;
|
||||||
|
|
||||||
|
public String out_trade_no;
|
||||||
|
|
||||||
|
public String device_info;
|
||||||
|
|
||||||
|
public String fee_type;
|
||||||
|
|
||||||
|
public String total_fee;
|
||||||
|
|
||||||
|
public String spbill_create_ip;
|
||||||
|
|
||||||
|
public String notify_url;
|
||||||
|
|
||||||
|
public String trade_type;
|
||||||
|
|
||||||
|
public String product_id;
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user