【发布时间】:2021-01-31 15:07:53
【问题描述】:
这段代码的目的是获取支付宝订单号并创建支付宝订单。首先,我们使用post方法向后端请求创建的订单号,然后使用获取到的订单号通过GET方式向支付宝请求支付。
由于GET方法中需要订单号,所以我将GET请求嵌套在POST之后。
浏览器模拟APP运行时,可以获取res,但是APP中axios.get中的res为null。
我的项目是vue嵌入APP的,我该怎么办?
axios.post(cloud_order, params, this.headers).then((res) => {
if (!res.code) {
this.orderId = res.data.order_no;
if (window.JSInterface) {
//android
window.JSInterface.toPay(this.orderId, this.money, this.payType);
} else {
//ios
let params = {
order_no: this.orderId,
subject: this.money,
};
axios.get(aliPay_ez, params, this.headers).then((res) => {
this.test.push(1);
this.test.push(res);
if (!res.code) {
let routerData = this.$router.resolve({
path: "/camera/applyText",
query: { htmls: res.data.order_info },
});
this.htmls = res.data.order_info;
const div = document.createElement("div");
div.innerHTML = this.htmls;
document.body.appendChild(div);
document.forms[0].submit();
} else {
this.$toast(res.message);
}
});
}
} else {
this.$toast(res.message);
}
});
【问题讨论】:
-
POST 不为空,GET 为空
-
不是,android也是
-
这个过程没有发生错误,所以catch错误什么都得不到。我在手机上使用了一个抓包工具,对后台返回的数据进行抓包。数据正常,但是前端没有拿到res。获取到的包里的res正常,但是前端得到了一个“正确”的null
-
我的意思是,我的VUE项目是运行在安卓和IOS平台上的,内嵌在APP中,所以安卓和IOS平台的浏览器无法获取这个资源,感谢anwser :)
-
不好意思,因为安卓APP自带支付方式,所以只需要创建一个订单号,不过我测试了一下,安卓中增加了GET方式,我还是没拿到 RES。
标签: javascript android ios vue.js