Commit acf4003d by xuzhenghua

登录

parent 10311673
...@@ -6,6 +6,7 @@ import {connect} from "react-redux" ...@@ -6,6 +6,7 @@ import {connect} from "react-redux"
import {addDays} from "date-fns" import {addDays} from "date-fns"
import cookie from "js-cookie" import cookie from "js-cookie"
import {setCurrentUser, startFetchUser} from "@/store/userAction" import {setCurrentUser, startFetchUser} from "@/store/userAction"
import {Toast} from "antd-mobile"
@connect(state => ({ @connect(state => ({
...@@ -32,6 +33,88 @@ class ML extends Component { ...@@ -32,6 +33,88 @@ class ML extends Component {
window['loginInfo'] = result => { window['loginInfo'] = result => {
_this.loginInfo(result) _this.loginInfo(result)
} }
if (browser.isWeixin) {
this.isweixinPay()
}
if (getParam('weixinpay')) {
this.payCallback()
}
}
// 微信内部支付回调
isweixinPay = () => {
let _this = this;
let weixin_code = getParam('code');
if (weixin_code) {
if (getParam('oid') === undefined) {
return
} else {
http.get(`${API['base-api']}/pay/wxpay/pub_charge/oid/${getParam('oid')}/code/${weixin_code}`).then((res) => {
if (res.data.errno === 0) {
let data = res.data.data;
function onBridgeReady() {
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
appId: data.appId, //公众号名称,由商户传入
timeStamp: data.timeStamp, //时间戳,自1970年以来的秒数
nonceStr: data.nonceStr, //随机串
package: data.package,
signType: data.signType, //微信签名方式:
paySign: data.paySign //微信签名
},
function (res) {
if (res.err_msg == "get_brand_wcpsys/order_status/ay_request:ok") {
Toast.info('支付成功', 2);
_this.intervalPayStatus = setInterval(function () {
http.get(`${API['base-api']}/m/orderState/oid/${getParam('oid')}`).then(res => {
if (res.data.errno === 401) {
clearInterval(_this.intervalPayStatus);
_this.intervalPayStatus = null;
location.reload()
}
})
}, 1000)
} else {
Toast.info('支付失败', 2);
}
}
)
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false)
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady)
}
} else {
onBridgeReady();
}
} else {
Toast.info(res.data.msg, 2)
}
})
}
}
}
// 支付完成之后获取状态
payCallback = () => {
const _this = this;
// 支付回调
// 定时器轮训获取订单状态
_this.intervalPayStatus = setInterval(function () {
http.get(`${API['base-api']}/m/orderState/oid/${getParam('oid')}`).then(res => {
if (res.data.errno === 401) {
clearInterval(_this.intervalPayStatus);
_this.intervalPayStatus = null;
location.reload()
}
})
}, 1000)
} }
// 获取app登录数据 // 获取app登录数据
...@@ -133,9 +216,9 @@ class ML extends Component { ...@@ -133,9 +216,9 @@ class ML extends Component {
<div> <div>
{ {
isPay === 0 && ( isPay === 0 && (
<PythonDes <PythonDes
backwardVersion={backwardVersion} backwardVersion={backwardVersion}
history={this.props.history} history={this.props.history}
isAppUpdate={isAppUpdate} isAppUpdate={isAppUpdate}
isPay={isPay} isPay={isPay}
/> />
......
...@@ -23,13 +23,6 @@ class PythonStudy extends Component { ...@@ -23,13 +23,6 @@ class PythonStudy extends Component {
componentDidMount() { componentDidMount() {
this.fetchCourseDetail() this.fetchCourseDetail()
if (browser.isWeixin) {
this.isweixinPay()
}
if (getParam('weixinpay')) {
this.payCallback()
}
} }
fetchCourseDetail = () => { fetchCourseDetail = () => {
...@@ -119,79 +112,7 @@ class PythonStudy extends Component { ...@@ -119,79 +112,7 @@ class PythonStudy extends Component {
}) })
} }
} }
// 微信支付
isweixinPay = () => {
let _this = this;
let weixin_code = getParam('code');
if (weixin_code) {
if (getParam('oid') === undefined) {
return
} else {
http.get(`${API['base-api']}/pay/wxpay/pub_charge/oid/${getParam('oid')}/code/${weixin_code}`).then((res) => {
if (res.data.errno === 0) {
let data = res.data.data;
function onBridgeReady() {
WeixinJSBridge.invoke(
'getBrandWCPayRequest', {
appId: data.appId, //公众号名称,由商户传入
timeStamp: data.timeStamp, //时间戳,自1970年以来的秒数
nonceStr: data.nonceStr, //随机串
package: data.package,
signType: data.signType, //微信签名方式:
paySign: data.paySign //微信签名
},
function (res) {
if (res.err_msg == "get_brand_wcpsys/order_status/ay_request:ok") {
Toast.info('支付成功', 2);
_this.intervalPayStatus = setInterval(function () {
http.get(`${API['base-api']}/m/orderState/oid/${getParam('oid')}`).then(res => {
if (res.data.errno === 401) {
clearInterval(_this.intervalPayStatus);
_this.intervalPayStatus = null;
location.reload()
}
})
}, 1000)
} else {
Toast.info('支付失败', 2);
}
}
)
}
if (typeof WeixinJSBridge == "undefined") {
if (document.addEventListener) {
document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false)
} else if (document.attachEvent) {
document.attachEvent('WeixinJSBridgeReady', onBridgeReady);
document.attachEvent('onWeixinJSBridgeReady', onBridgeReady)
}
} else {
onBridgeReady();
}
} else {
Toast.info(res.data.msg, 2)
}
})
}
}
}
// 支付完成之后获取状态
payCallback = () => {
const _this = this;
// 支付回调
// 定时器轮训获取订单状态
_this.intervalPayStatus = setInterval(function () {
http.get(`${API['base-api']}/m/orderState/oid/${getParam('oid')}`).then(res => {
if (res.data.errno === 401) {
clearInterval(_this.intervalPayStatus);
_this.intervalPayStatus = null;
location.reload()
}
})
}, 1000)
}
render() { render() {
const {user} = this.props const {user} = this.props
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment