48 lines
1.5 KiB
JavaScript
48 lines
1.5 KiB
JavaScript
import BasePlatform from './BasePlatform';
|
||
|
||
class H5Platform extends BasePlatform {
|
||
constructor() {
|
||
super();
|
||
this.code = 'WEB_H5';
|
||
this.env = 'h5';
|
||
}
|
||
getPayData(url, data) {
|
||
|
||
data['quitUrl']=escape(window.location.href);
|
||
data['returnUrl']=escape(window.location.href);
|
||
console.log('处理数据',data);
|
||
return data;
|
||
}
|
||
pay({ data }) {
|
||
console.log('支付1111');
|
||
|
||
return new Promise((resolve) => {
|
||
console.log(data);
|
||
// 创建一个临时div元素
|
||
const tempDiv = document.createElement('div');
|
||
// 将data作为HTML插入到div中(假设data是表单的HTML字符串)
|
||
tempDiv.innerHTML = data;
|
||
// 将表单添加到body中
|
||
document.body.appendChild(tempDiv.firstChild);
|
||
// 获取表单并提交
|
||
const form = document.getElementById('alipaysubmit');
|
||
if (form) {
|
||
form.submit();
|
||
resolve({ success: true });
|
||
} else {
|
||
resolve({ success: false, message: '表单创建失败' });
|
||
}
|
||
});
|
||
}
|
||
|
||
share({ title, desc, image, url }) {
|
||
console.log(`H5分享:${title} - ${desc}`);
|
||
// 调用浏览器原生分享(如果可用)
|
||
if (navigator.share) {
|
||
return navigator.share({ title, text: desc, url });
|
||
}
|
||
// 降级方案
|
||
alert(`请手动分享:${url}`);
|
||
}
|
||
}
|
||
export default H5Platform; |