mirror of
https://gitee.com/hhyykk/ipms-sjy.git
synced 2025-07-15 11:35:06 +08:00
多模块重构 12:【新增】Spring Security 新增 AuthorizeRequestsCustomizer 抽象类, 自定义每个 Maven Module 的 URL 的安全配置
This commit is contained in:
@ -0,0 +1,4 @@
|
||||
/**
|
||||
* 占位
|
||||
*/
|
||||
package cn.iocoder.yudao.module.shop.controller.admin;
|
@ -0,0 +1,74 @@
|
||||
package cn.iocoder.yudao.module.shop.controller.app;
|
||||
|
||||
import cn.iocoder.yudao.framework.common.pojo.CommonResult;
|
||||
import cn.iocoder.yudao.framework.common.util.date.DateUtils;
|
||||
import cn.iocoder.yudao.module.pay.service.notify.vo.PayNotifyOrderReqVO;
|
||||
import cn.iocoder.yudao.module.pay.service.notify.vo.PayRefundOrderReqVO;
|
||||
import cn.iocoder.yudao.module.pay.service.order.PayOrderService;
|
||||
import cn.iocoder.yudao.module.pay.service.order.dto.PayOrderCreateReqDTO;
|
||||
import cn.iocoder.yudao.module.pay.util.PaySeqUtils;
|
||||
import cn.iocoder.yudao.module.shop.controller.app.vo.AppShopOrderCreateRespVO;
|
||||
import io.swagger.annotations.Api;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.validation.Valid;
|
||||
import java.time.Duration;
|
||||
|
||||
import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;
|
||||
import static cn.iocoder.yudao.framework.common.util.servlet.ServletUtils.getClientIP;
|
||||
|
||||
@Api(tags = "用户 APP - 商城订单")
|
||||
@RestController
|
||||
@RequestMapping("/shop/order")
|
||||
@Validated
|
||||
@Slf4j
|
||||
public class AppShopOrderController {
|
||||
|
||||
@Resource
|
||||
private PayOrderService payOrderService;
|
||||
|
||||
@PostMapping("/create")
|
||||
@ApiOperation("创建商城订单")
|
||||
// @PreAuthenticated // TODO 暂时不加登陆验证,前端暂时没做好
|
||||
public CommonResult<AppShopOrderCreateRespVO> create() {
|
||||
// 假装创建商城订单
|
||||
Long shopOrderId = System.currentTimeMillis();
|
||||
|
||||
// 创建对应的支付订单
|
||||
PayOrderCreateReqDTO reqDTO = new PayOrderCreateReqDTO();
|
||||
reqDTO.setAppId(6L);
|
||||
reqDTO.setUserIp(getClientIP());
|
||||
reqDTO.setMerchantOrderId(PaySeqUtils.genMerchantOrderNo());
|
||||
reqDTO.setSubject("标题:" + shopOrderId);
|
||||
reqDTO.setBody("内容:" + shopOrderId);
|
||||
reqDTO.setAmount(200); // 单位:分
|
||||
reqDTO.setExpireTime(DateUtils.addTime(Duration.ofDays(1)));
|
||||
Long payOrderId = payOrderService.createPayOrder(reqDTO);
|
||||
|
||||
// 拼接返回
|
||||
return success(AppShopOrderCreateRespVO.builder().id(shopOrderId)
|
||||
.payOrderId(payOrderId).build());
|
||||
}
|
||||
|
||||
@PostMapping("/pay-notify")
|
||||
@ApiOperation("支付回调")
|
||||
public CommonResult<Boolean> payNotify(@RequestBody @Valid PayNotifyOrderReqVO reqVO) {
|
||||
log.info("[payNotify][回调成功]");
|
||||
return success(true);
|
||||
}
|
||||
|
||||
@PostMapping("/refund-notify")
|
||||
@ApiOperation("退款回调")
|
||||
public CommonResult<Boolean> refundNotify(@RequestBody @Valid PayRefundOrderReqVO reqVO) {
|
||||
log.info("[refundNotify][回调成功]");
|
||||
return success(true);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package cn.iocoder.yudao.module.shop.controller.app.vo;
|
||||
|
||||
import io.swagger.annotations.ApiModel;
|
||||
import io.swagger.annotations.ApiModelProperty;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Builder;
|
||||
import lombok.Data;
|
||||
|
||||
@ApiModel("用户 APP - 商城订单创建 Response VO")
|
||||
@Data
|
||||
@Builder
|
||||
@AllArgsConstructor
|
||||
public class AppShopOrderCreateRespVO {
|
||||
|
||||
@ApiModelProperty(value = "商城订单编号", required = true, example = "1024")
|
||||
private Long id;
|
||||
|
||||
@ApiModelProperty(value = "支付订单编号", required = true, example = "2048")
|
||||
private Long payOrderId;
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* shop 包下,我们放商城业务
|
||||
* 例如说:商品、订单等等
|
||||
* 注意,目前仅仅作为 demo 演示,对接 pay 支付系统
|
||||
*
|
||||
* 缩写:shop
|
||||
*/
|
||||
// TODO 芋艿:后续会迁移到 yudao-module-mall-trade 下
|
||||
package cn.iocoder.yudao.module.shop;
|
@ -1,9 +0,0 @@
|
||||
package cn.iocoder.yudao.server.framework.monitor.config;
|
||||
|
||||
import de.codecentric.boot.admin.server.config.EnableAdminServer;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
@EnableAdminServer
|
||||
public class AdminServerConfiguration {
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
/**
|
||||
* 使用 Spring Boot Admin 实现简单的监控平台
|
||||
*/
|
||||
package cn.iocoder.yudao.server.framework.monitor;
|
@ -1 +0,0 @@
|
||||
<http://www.iocoder.cn/Spring-Boot/Admin/?yudao>
|
@ -1,50 +0,0 @@
|
||||
package cn.iocoder.yudao.server.framework.security;
|
||||
|
||||
import cn.iocoder.yudao.framework.web.config.WebProperties;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.Customizer;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configurers.ExpressionUrlAuthorizationConfigurer;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
|
||||
@Configuration
|
||||
public class SecurityConfiguration {
|
||||
|
||||
@Resource
|
||||
private WebProperties webProperties;
|
||||
|
||||
@Value("${spring.boot.admin.context-path:''}")
|
||||
private String adminSeverContextPath;
|
||||
|
||||
@Bean
|
||||
public Customizer<ExpressionUrlAuthorizationConfigurer<HttpSecurity>.ExpressionInterceptUrlRegistry> authorizeRequestsCustomizer() {
|
||||
return registry -> {
|
||||
// 验证码的接口
|
||||
registry.antMatchers(buildAdminApi("/system/captcha/**")).anonymous();
|
||||
// 获得租户编号的接口
|
||||
registry.antMatchers(buildAdminApi("/system/tenant/get-id-by-name")).anonymous();
|
||||
// Spring Boot Admin Server 的安全配置
|
||||
registry.antMatchers(adminSeverContextPath).anonymous()
|
||||
.antMatchers(adminSeverContextPath + "/**").anonymous();
|
||||
// 短信回调 API
|
||||
registry.antMatchers(buildAdminApi("/system/sms/callback/**")).anonymous();
|
||||
|
||||
// 设置 App API 无需认证
|
||||
registry.antMatchers(buildAppApi("/**")).permitAll();
|
||||
};
|
||||
}
|
||||
|
||||
private String buildAdminApi(String url) {
|
||||
// TODO 芋艿:多模块
|
||||
return webProperties.getAdminApi().getPrefix() + url;
|
||||
}
|
||||
|
||||
private String buildAppApi(String url) {
|
||||
// TODO 芋艿:多模块
|
||||
return webProperties.getAppApi().getPrefix() + url;
|
||||
}
|
||||
|
||||
}
|
@ -20,6 +20,10 @@ spring:
|
||||
write-durations-as-timestamps: true # 设置 Duration 的格式,使用时间戳
|
||||
fail-on-empty-beans: false # 允许序列化无属性的 Bean
|
||||
|
||||
# 静态资源
|
||||
mvc:
|
||||
static-path-pattern: /static/**
|
||||
|
||||
# 工作流 Activiti 配置
|
||||
activiti:
|
||||
# 1. false: 默认值,activiti启动时,对比数据库表中保存的版本,如果不匹配。将抛出异常
|
||||
|
@ -0,0 +1 @@
|
||||
DKOvVzFP7vPwwHx2
|
13
yudao-server/src/main/resources/static/READMD.md
Normal file
13
yudao-server/src/main/resources/static/READMD.md
Normal file
@ -0,0 +1,13 @@
|
||||
## 微信公众号
|
||||
|
||||
参考文章:https://www.yuque.com/docs/share/0e2966dd-89f8-4b69-980d-b876168725df
|
||||
|
||||
① 访问 social-login.html 选择【微信公众号】
|
||||
|
||||
② 微信公众号授权完成后,跳转回 social-login2.html,输入手机号 + 密码,进行绑定
|
||||
|
||||
## 微信小程序
|
||||
|
||||
参考文章:https://www.yuque.com/docs/share/88e3d30a-6830-45fc-8c25-dae485aef3aa
|
||||
|
||||
① 暂时使用 mini-program-test 项目
|
79
yudao-server/src/main/resources/static/pay_alipay_qr.html
Normal file
79
yudao-server/src/main/resources/static/pay_alipay_qr.html
Normal file
@ -0,0 +1,79 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
|
||||
<title>支付测试页</title>
|
||||
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
|
||||
<script src="qrcode.min.js" type="text/javascript"></script>
|
||||
|
||||
</head>
|
||||
<body>
|
||||
<div>点击如下按钮,发起支付宝扫码支付的测试</div>
|
||||
<div>
|
||||
<button id="alipay_wap">支付宝扫码支付</button>
|
||||
</div>
|
||||
<div id="qrcode"></div>
|
||||
</body>
|
||||
<style>
|
||||
#qrcode{
|
||||
padding-left: 20px;
|
||||
padding-top: 20px;
|
||||
}
|
||||
</style>
|
||||
<script>
|
||||
let shopOrderId = undefined;
|
||||
let payOrderId = undefined;
|
||||
let server = 'http://127.0.0.1:48080';
|
||||
$(function() {
|
||||
// 自动发起商城订单编号
|
||||
$.ajax({
|
||||
url: server + "/app-api/shop/order/create",
|
||||
method: 'POST',
|
||||
success: function( result ) {
|
||||
if (result.code !== 0) {
|
||||
alert('创建商城订单失败,原因:' + result.msg)
|
||||
return;
|
||||
}
|
||||
shopOrderId = result.data.id;
|
||||
payOrderId = result.data.payOrderId;
|
||||
console.log("商城订单:" + shopOrderId)
|
||||
console.log("支付订单:" + payOrderId)
|
||||
}
|
||||
})
|
||||
});
|
||||
// 支付宝扫码支付
|
||||
$( "#alipay_wap").on( "click", function() {
|
||||
// 提交支付
|
||||
$.ajax({
|
||||
url: server + "/app-api/pay/order/submit",
|
||||
method: 'POST',
|
||||
dataType: "json",
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify({
|
||||
"id": payOrderId,
|
||||
"channelCode": 'alipay_qr'
|
||||
}),
|
||||
success: function( result ) {
|
||||
if (result.code !== 0) {
|
||||
alert('提交支付订单失败,原因:' + result.msg)
|
||||
return;
|
||||
}
|
||||
//提交支付后返回的参数
|
||||
let data = result.data.invokeResponse;
|
||||
new QRCode($("#qrcode")[0],{
|
||||
text: data.qrCode, //内容
|
||||
width:98, //宽度
|
||||
height:98, //高度
|
||||
correctLevel: 3,//二维码纠错级别
|
||||
background: "#ffffff",//背景颜色
|
||||
foreground: "#000000"//二维码颜色
|
||||
});
|
||||
|
||||
console.log("data.qrCode===",data.qrCode)
|
||||
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
</html>
|
65
yudao-server/src/main/resources/static/pay_alipay_wap.html
Normal file
65
yudao-server/src/main/resources/static/pay_alipay_wap.html
Normal file
@ -0,0 +1,65 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
|
||||
<title>支付测试页</title>
|
||||
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div>点击如下按钮,发起支付的测试</div>
|
||||
<div>
|
||||
<button id="alipay_wap">支付宝手机网站支付</button>
|
||||
</div>
|
||||
<div id="dynamic_form"></div>
|
||||
</body>
|
||||
<script>
|
||||
|
||||
let shopOrderId = undefined;
|
||||
let payOrderId = undefined;
|
||||
let server = 'http://127.0.0.1:48080';
|
||||
//let server = 'http://niubi.natapp1.cc';
|
||||
|
||||
$(function() {
|
||||
// 自动发起商城订单编号
|
||||
$.ajax({
|
||||
url: server + "/app-api/shop/order/create",
|
||||
method: 'POST',
|
||||
success: function( result ) {
|
||||
if (result.code !== 0) {
|
||||
alert('创建商城订单失败,原因:' + result.msg)
|
||||
return;
|
||||
}
|
||||
shopOrderId = result.data.id;
|
||||
payOrderId = result.data.payOrderId;
|
||||
console.log("商城订单:" + shopOrderId)
|
||||
console.log("支付订单:" + payOrderId)
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
$( "#alipay_wap").on( "click", function() {
|
||||
// 提交支付
|
||||
$.ajax({
|
||||
url: server + "/app-api/pay/order/submit",
|
||||
method: 'POST',
|
||||
dataType: "json",
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify({
|
||||
"id": payOrderId,
|
||||
"channelCode": 'alipay_wap'
|
||||
}),
|
||||
success: function( result ) {
|
||||
if (result.code !== 0) {
|
||||
alert('提交支付订单失败,原因:' + result.msg)
|
||||
return;
|
||||
}
|
||||
alert('点击确定,开始支付');
|
||||
//支付宝 手机WAP 返回表单,自动跳到支付宝支付页面
|
||||
let data = result.data.invokeResponse;
|
||||
$("#dynamic_form").html(data.body);
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
</html>
|
117
yudao-server/src/main/resources/static/pay_wx_pub.html
Normal file
117
yudao-server/src/main/resources/static/pay_wx_pub.html
Normal file
@ -0,0 +1,117 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
|
||||
<title>支付测试页</title>
|
||||
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
|
||||
<script src="http://res.wx.qq.com/open/js/jweixin-1.6.0.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div>点击如下按钮,发起支付的测试</div>
|
||||
<div>
|
||||
<button id="wx_pub">微信公众号</button>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
let shopOrderId = undefined;
|
||||
let payOrderId = undefined;
|
||||
// let server = 'http://127.0.0.1:48080';
|
||||
let server = 'http://niubi.natapp1.cc';
|
||||
// TODO openid
|
||||
let openid = "ockUAwIZ-0OeMZl9ogcZ4ILrGba0";
|
||||
$(function() {
|
||||
// 获得 JsapiTicket
|
||||
// 参考 https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html 文档
|
||||
$.ajax({
|
||||
url: server + "/app-api/wx/mp/create-jsapi-signature?url=" + document.location.href,
|
||||
method: 'POST',
|
||||
success: function( result ) {
|
||||
if (result.code !== 0) {
|
||||
alert('获取 JsapiTicket 失败,原因:' + result.msg)
|
||||
return;
|
||||
}
|
||||
var jsapiTicket = result.data;
|
||||
jsapiTicket.jsApiList = ['chooseWXPay'];
|
||||
jsapiTicket.debug = false;
|
||||
|
||||
// 初始化 JS
|
||||
wx.config(jsapiTicket);
|
||||
}
|
||||
});
|
||||
|
||||
// 自动发起商城订单编号
|
||||
$.ajax({
|
||||
url: server + "/app-api/shop/order/create",
|
||||
method: 'POST',
|
||||
success: function( result ) {
|
||||
if (result.code !== 0) {
|
||||
alert('创建商城订单失败,原因:' + result.msg)
|
||||
return;
|
||||
}
|
||||
shopOrderId = result.data.id;
|
||||
payOrderId = result.data.payOrderId;
|
||||
console.log("商城订单:" + shopOrderId)
|
||||
console.log("支付订单:" + payOrderId)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
// 微信公众号
|
||||
$( "#wx_pub").on( "click", function() {
|
||||
if (typeof WeixinJSBridge == "undefined") {
|
||||
// if (document.addEventListener) {
|
||||
// document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
|
||||
// } else if (document.attachEvent) {
|
||||
// document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
|
||||
// document.attachEvent('onWeixinJSBridgeReady', onBridgeReady);
|
||||
// }
|
||||
alert('微信支付,只支持在微信客户端中使用!');
|
||||
return;
|
||||
}
|
||||
if (navigator.userAgent.indexOf('wechatdevtools') >= 0) {
|
||||
alert('微信支付,无法在微信开发者工具中使用!请使用微信客户端!');
|
||||
return;
|
||||
}
|
||||
|
||||
// 提交支付
|
||||
// 参考 https://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7&index=6 文档
|
||||
// 参考 https://segmentfault.com/a/1190000020704650 文档
|
||||
$.ajax({
|
||||
url: server + "/app-api/pay/order/submit",
|
||||
method: 'POST',
|
||||
dataType: "json",
|
||||
contentType: "application/json",
|
||||
data: JSON.stringify({
|
||||
"id": payOrderId,
|
||||
"channelCode": 'wx_pub',
|
||||
"channelExtras": {
|
||||
"openid": openid
|
||||
}
|
||||
}),
|
||||
success: function( result ) {
|
||||
if (result.code !== 0) {
|
||||
alert('提交支付订单失败,原因:' + result.msg)
|
||||
return;
|
||||
}
|
||||
alert('点击确定,开始微信支付');
|
||||
// 开始调用微信支付
|
||||
let data = result.data.invokeResponse;
|
||||
wx.chooseWXPay({
|
||||
timestamp: data.timeStamp,
|
||||
nonceStr: data.nonceStr,
|
||||
package: data.packageValue,
|
||||
signType: data.signType,
|
||||
paySign: data.paySign,
|
||||
success: function (res) {
|
||||
alert(JSON.stringify(res));
|
||||
},
|
||||
error: function(e) {
|
||||
alert(JSON.stringify(e));
|
||||
}
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
</html>
|
1
yudao-server/src/main/resources/static/qrcode.min.js
vendored
Normal file
1
yudao-server/src/main/resources/static/qrcode.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
38
yudao-server/src/main/resources/static/social-login.html
Normal file
38
yudao-server/src/main/resources/static/social-login.html
Normal file
@ -0,0 +1,38 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
|
||||
<title>社交登陆测试页</title>
|
||||
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div>点击如下按钮,发起登陆的测试</div>
|
||||
<div>
|
||||
<button id="wx_pub">微信公众号</button>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
// let server = 'http://127.0.0.1:28080';
|
||||
let server = 'http://192.168.1.2:48080';
|
||||
|
||||
|
||||
// 微信公众号
|
||||
$( "#wx_pub").on( "click", function() {
|
||||
// 获得授权链接
|
||||
$.ajax({
|
||||
url: server + "/app-api/social-auth-redirect?type=31&redirectUri=" +
|
||||
encodeURIComponent(server + '/static/social-login2.html'), //重定向地址
|
||||
method: 'GET',
|
||||
success: function( result ) {
|
||||
if (result.code !== 0) {
|
||||
alert('获得授权链接失败,原因:' + result.msg)
|
||||
return;
|
||||
}
|
||||
// 跳转重定向
|
||||
document.location.href = result.data;
|
||||
}
|
||||
})
|
||||
});
|
||||
</script>
|
||||
</html>
|
87
yudao-server/src/main/resources/static/social-login2.html
Normal file
87
yudao-server/src/main/resources/static/social-login2.html
Normal file
@ -0,0 +1,87 @@
|
||||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no"/>
|
||||
<title>社交登陆测试页</title>
|
||||
<script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.6.0/jquery.js"></script>
|
||||
</head>
|
||||
<body>
|
||||
<div>点击如下按钮,授权登录</div>
|
||||
<div>
|
||||
手机号<input id="mobile" value="15601691300"><br>
|
||||
手机验证码<input id="smsCode">
|
||||
<button id="send_sms_code">发送手机验证码</button>
|
||||
<br>
|
||||
<button id="wx_pub">微信公众号授权登录</button>
|
||||
</div>
|
||||
</body>
|
||||
<script>
|
||||
// let server = 'http://127.0.0.1:48080';
|
||||
let server = 'http://192.168.1.2:48080';
|
||||
|
||||
let type = 31; //登录类型 微信公众号
|
||||
|
||||
// 微信公众号
|
||||
$("#wx_pub").on("click", function () {
|
||||
let code = getUrlParam("code"); // 访问授权连接后,会回调本页面地址,参数在本页面url后面
|
||||
let state = getUrlParam("state");
|
||||
console.log("获取code: " + code + ", state: " + state)
|
||||
|
||||
let data = {
|
||||
'mobile': $('#mobile').val(),
|
||||
'smsCode': $('#smsCode').val(),
|
||||
'code': code,
|
||||
'state': state,
|
||||
'type': type
|
||||
}
|
||||
|
||||
// 调用授权登录接口
|
||||
$.ajax({
|
||||
url: server + "/app-api/social-login2",
|
||||
method: 'POST',
|
||||
data: JSON.stringify(data),
|
||||
contentType: "application/json;charset=utf-8",
|
||||
dataType: "json",
|
||||
success: function( result ) {
|
||||
if (result.code !== 0) {
|
||||
alert('调用授权登录接口失败,原因:' + result.msg)
|
||||
return;
|
||||
}
|
||||
alert("授权登录成功, token: "+result.data.token)
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
// 发送手机验证码
|
||||
$("#send_sms_code").on("click", function () {
|
||||
let data = {
|
||||
'mobile': $('#mobile').val(),
|
||||
'scene': 1 // 手机号登陆 类型
|
||||
}
|
||||
$.ajax({
|
||||
url: server + "/app-api/send-sms-code",
|
||||
method: 'POST',
|
||||
data: JSON.stringify(data),
|
||||
contentType: "application/json;charset=utf-8",
|
||||
dataType: "json",
|
||||
success: function (result) {
|
||||
if (result.code !== 0) {
|
||||
alert('发送手机验证码失败,原因:' + result.msg)
|
||||
return;
|
||||
}
|
||||
alert("发送成功, 请查看日志");
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
//获取url中的参数
|
||||
function getUrlParam(name) {
|
||||
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
|
||||
var r = window.location.search.substr(1).match(reg); //匹配目标参数
|
||||
if (r != null) return unescape(r[2]);
|
||||
return null; //返回参数值
|
||||
}
|
||||
</script>
|
||||
</html>
|
Reference in New Issue
Block a user