|
@@ -10,6 +10,8 @@ import {
|
|
|
ToastController,
|
|
|
LoadingController,
|
|
|
} from '../../../modules/ionic-standalone.modules';
|
|
|
+import { DeviceService } from '../../../services/device.service';
|
|
|
+import { SafariViewController } from '@ionic-native/safari-view-controller/ngx';
|
|
|
declare var wx: any;
|
|
|
|
|
|
@Component({
|
|
@@ -37,7 +39,7 @@ export class PayCompComponent implements OnInit {
|
|
|
user: Parse.Object = Parse.User.current()!;
|
|
|
timer: any; //定时查询
|
|
|
accountLog?: Parse.Object; // 充值记录
|
|
|
- loading:any //等待
|
|
|
+ loading: any //等待
|
|
|
constructor(
|
|
|
private accServ: AccountService,
|
|
|
private toastController: ToastController,
|
|
@@ -45,7 +47,9 @@ export class PayCompComponent implements OnInit {
|
|
|
private http: HttpClient,
|
|
|
private activRoute: ActivatedRoute,
|
|
|
private loadingCtrl: LoadingController,
|
|
|
- ) {}
|
|
|
+ private deviceSer: DeviceService,
|
|
|
+ private safariViewController: SafariViewController
|
|
|
+ ) { }
|
|
|
|
|
|
ngOnInit() {
|
|
|
this.activRoute.paramMap.subscribe((params) => {
|
|
@@ -58,6 +62,9 @@ export class PayCompComponent implements OnInit {
|
|
|
}
|
|
|
});
|
|
|
}
|
|
|
+ ngOnDestroy(): void {
|
|
|
+ this.timer && clearInterval(this.timer);
|
|
|
+ }
|
|
|
onchangPay(val: string) {
|
|
|
this.checkpay = val;
|
|
|
console.log(val);
|
|
@@ -185,7 +192,7 @@ export class PayCompComponent implements OnInit {
|
|
|
{
|
|
|
role: 'ok',
|
|
|
text: '确认',
|
|
|
- handler: () => {},
|
|
|
+ handler: () => { },
|
|
|
},
|
|
|
],
|
|
|
});
|
|
@@ -225,29 +232,48 @@ export class PayCompComponent implements OnInit {
|
|
|
try {
|
|
|
this.isDisabled = true;
|
|
|
await this.getOrderId();
|
|
|
- let data: any = await this.getAliPayUrl();
|
|
|
- console.log(data);
|
|
|
-
|
|
|
- const tempDiv = document.createElement('div');
|
|
|
- tempDiv.innerHTML = data.pay_url; // 假设data.pay_url是完整的HTML字符串
|
|
|
- const formElement = tempDiv.querySelector('form');
|
|
|
- if (formElement) {
|
|
|
- // 阻止默认行为,避免页面刷新
|
|
|
- formElement.addEventListener('submit', (event) => {
|
|
|
- event.preventDefault();
|
|
|
+ let htmlStringOrUrl: any = await this.getAliPayUrl();
|
|
|
+ console.log(htmlStringOrUrl);
|
|
|
+ if (this.deviceSer.isIOS) {
|
|
|
+ this.safariViewController.show({
|
|
|
+ url: htmlStringOrUrl,
|
|
|
+ hidden: false,
|
|
|
+ animated: true,
|
|
|
+ transition: 'curl'
|
|
|
+ }).subscribe((result: any) => {
|
|
|
+ if (result.event === 'opened') {
|
|
|
+ console.log('Opened');
|
|
|
+ } else if (result.event === 'loaded') {
|
|
|
+ console.log('Loaded');
|
|
|
+ } else if (result.event === 'closed') {
|
|
|
+ console.log('Closed');
|
|
|
+ }
|
|
|
+ }, (error: any) => {
|
|
|
+ console.log(error);
|
|
|
});
|
|
|
- // 添加隐藏的iframe来提交表单
|
|
|
- const iframe = document.createElement('iframe');
|
|
|
- iframe.style.display = 'none';
|
|
|
- document.body.appendChild(iframe);
|
|
|
- formElement.target = iframe.name;
|
|
|
-
|
|
|
- document.body.appendChild(formElement);
|
|
|
- formElement.submit();
|
|
|
- document.body.removeChild(formElement); // 提交后移除表单元素
|
|
|
} else {
|
|
|
- console.error('未找到表单元素');
|
|
|
- this.loading?.dismiss();
|
|
|
+ const tempDiv = document.createElement('div');
|
|
|
+ tempDiv.innerHTML = htmlStringOrUrl; // 假设htmlString是完整的HTML字符串
|
|
|
+ const formElement = tempDiv.querySelector('form');
|
|
|
+ if (formElement) {
|
|
|
+ // 阻止默认行为,避免页面刷新
|
|
|
+ formElement.addEventListener('submit', (event) => {
|
|
|
+ event.preventDefault();
|
|
|
+ });
|
|
|
+ // 添加隐藏的iframe来提交表单
|
|
|
+ const iframe = document.createElement('iframe');
|
|
|
+ iframe.style.display = 'none';
|
|
|
+ document.body.appendChild(iframe);
|
|
|
+ formElement.target = iframe.name;
|
|
|
+ console.log(formElement);
|
|
|
+
|
|
|
+ document.body.appendChild(formElement);
|
|
|
+ formElement.submit();
|
|
|
+ document.body.removeChild(formElement); // 提交后移除表单元素
|
|
|
+ } else {
|
|
|
+ console.error('未找到表单元素');
|
|
|
+ this.loading?.dismiss();
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
this.timer = setInterval(async () => {
|
|
@@ -286,7 +312,7 @@ export class PayCompComponent implements OnInit {
|
|
|
{
|
|
|
role: 'ok',
|
|
|
text: '确认',
|
|
|
- handler: () => {},
|
|
|
+ handler: () => { },
|
|
|
},
|
|
|
],
|
|
|
});
|
|
@@ -304,6 +330,7 @@ export class PayCompComponent implements OnInit {
|
|
|
tradetype: 'wap',
|
|
|
orderTitle: this.title,
|
|
|
returnUrl: beforURL,
|
|
|
+ returnType: this.deviceSer.isIOS ? 'get' : 'post',
|
|
|
};
|
|
|
try {
|
|
|
this.http
|
|
@@ -314,7 +341,7 @@ export class PayCompComponent implements OnInit {
|
|
|
return;
|
|
|
}
|
|
|
if (res.data && res.data.pay_url) {
|
|
|
- resolve(res.data);
|
|
|
+ resolve(res.data.pay_url);
|
|
|
}
|
|
|
});
|
|
|
} catch (err) {
|
|
@@ -392,7 +419,7 @@ export class PayCompComponent implements OnInit {
|
|
|
});
|
|
|
}
|
|
|
})
|
|
|
- .catch((err) => {});
|
|
|
+ .catch((err) => { });
|
|
|
}, 3000);
|
|
|
}
|
|
|
|