|
@@ -212,23 +212,33 @@ export class PayCompComponent implements OnInit {
|
|
|
});
|
|
|
}
|
|
|
|
|
|
-
|
|
|
/* 支付宝支付 */
|
|
|
- async openAlipay(){
|
|
|
+ async openAlipay() {
|
|
|
if (this.isDisabled) return;
|
|
|
try {
|
|
|
this.isDisabled = true;
|
|
|
await this.getOrderId();
|
|
|
- let data:any = await this.getAliPayUrl();
|
|
|
- console.log(data.pay_url);
|
|
|
- window.open(data.pay_url, "newW");
|
|
|
+ let data: any = await this.getAliPayUrl();
|
|
|
+ console.log(data);
|
|
|
+ // window.open(data.pay_url, "newW");
|
|
|
+ // 创建一个临时的div元素来解析HTML字符串
|
|
|
+ const tempDiv = document.createElement('div');
|
|
|
+ tempDiv.innerHTML = data.pay_url; // 假设data.pay_url是完整的HTML字符串
|
|
|
+ const formElement = tempDiv.querySelector('form');
|
|
|
+ if (formElement) {
|
|
|
+ document.body.appendChild(formElement);
|
|
|
+ formElement.submit();
|
|
|
+ document.body.removeChild(formElement); // 提交后移除表单元素
|
|
|
+ } else {
|
|
|
+ console.error('未找到表单元素');
|
|
|
+ }
|
|
|
this.timer = setInterval(async () => {
|
|
|
- console.log("支付结果轮询");
|
|
|
- let AccountLog = new Parse.Query("AccountLog");
|
|
|
- AccountLog.equalTo("company", this.accServ.company);
|
|
|
- AccountLog.equalTo("orderNumber", this.tradeNo);
|
|
|
- AccountLog.equalTo("payType", "aliPay");
|
|
|
- AccountLog.equalTo("isVerified", true);
|
|
|
+ console.log('支付结果轮询');
|
|
|
+ let AccountLog = new Parse.Query('AccountLog');
|
|
|
+ AccountLog.equalTo('company', this.accServ.company);
|
|
|
+ AccountLog.equalTo('orderNumber', this.tradeNo);
|
|
|
+ AccountLog.equalTo('payType', 'aliPay');
|
|
|
+ AccountLog.equalTo('isVerified', true);
|
|
|
let result = await AccountLog.first();
|
|
|
if (result && result.id) {
|
|
|
clearInterval(this.timer);
|
|
@@ -245,7 +255,7 @@ export class PayCompComponent implements OnInit {
|
|
|
});
|
|
|
}
|
|
|
}, 1000);
|
|
|
- }catch (err: any) {
|
|
|
+ } catch (err: any) {
|
|
|
this.isDisabled = false;
|
|
|
let alert = await this.alertCtrl.create({
|
|
|
header: '异常错误',
|
|
@@ -262,39 +272,39 @@ export class PayCompComponent implements OnInit {
|
|
|
alert.present();
|
|
|
}
|
|
|
}
|
|
|
- // 获取支付宝支付
|
|
|
- async getAliPayUrl() {
|
|
|
- return new Promise((resolve, reject) => {
|
|
|
- let beforURL = window.location.href;
|
|
|
- let params = {
|
|
|
- company: this.accServ.company,
|
|
|
- tradeNo: this.tradeNo,
|
|
|
- price: this.price,
|
|
|
- tradetype:'wap',
|
|
|
- // price: 0.01,
|
|
|
- orderTitle: this.title,
|
|
|
- returnUrl: beforURL,
|
|
|
- };
|
|
|
- try {
|
|
|
- this.http
|
|
|
- .post("https://server.fmode.cn/api/alipay/neworder", params)
|
|
|
- .subscribe((res: any) => {
|
|
|
- if (res.code !== 200) {
|
|
|
- this.toast('网络错误,请稍后重试', 'warning');
|
|
|
- return
|
|
|
- }
|
|
|
- if (res.data && res.data.pay_url) {
|
|
|
- resolve(res.data);
|
|
|
- }
|
|
|
- });
|
|
|
- } catch (err) {
|
|
|
- if (err) {
|
|
|
- this.toast('网络错误,请稍后重试', 'warning');
|
|
|
- reject(err);
|
|
|
- }
|
|
|
+ // 获取支付宝支付
|
|
|
+ async getAliPayUrl() {
|
|
|
+ return new Promise((resolve, reject) => {
|
|
|
+ let beforURL = window.location.href;
|
|
|
+ let params = {
|
|
|
+ company: this.accServ.company,
|
|
|
+ tradeNo: this.tradeNo,
|
|
|
+ price: this.price,
|
|
|
+ tradetype: 'wap',
|
|
|
+ // price: 0.01,
|
|
|
+ orderTitle: this.title,
|
|
|
+ returnUrl: beforURL,
|
|
|
+ };
|
|
|
+ try {
|
|
|
+ this.http
|
|
|
+ .post('https://server.fmode.cn/api/alipay/neworder', params)
|
|
|
+ .subscribe((res: any) => {
|
|
|
+ if (res.code !== 200) {
|
|
|
+ this.toast('网络错误,请稍后重试', 'warning');
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ if (res.data && res.data.pay_url) {
|
|
|
+ resolve(res.data);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ } catch (err) {
|
|
|
+ if (err) {
|
|
|
+ this.toast('网络错误,请稍后重试', 'warning');
|
|
|
+ reject(err);
|
|
|
}
|
|
|
- });
|
|
|
- }
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
|
|
|
/* 关闭支付弹窗 */
|
|
|
onClose() {
|