118 lines
4.1 KiB
JavaScript
118 lines
4.1 KiB
JavaScript
"use strict";
|
|
const common_vendor = require("../../common/vendor.js");
|
|
const _sfc_main = {
|
|
__name: "index",
|
|
setup(__props) {
|
|
const amount = common_vendor.ref("");
|
|
const loading = common_vendor.ref(false);
|
|
const statusMessage = common_vendor.ref("");
|
|
common_vendor.ref({
|
|
timeStamp: "1747983532",
|
|
package: "prepay_id=wx23145806465232c82870c59d2d41cf0000",
|
|
paySign: "0pUqj2JZ77BYchyJuthQyP4yRfqhjvwag78Q4IMnIyQ3/OQP6OyJreZfmj0GFSEMrRsKAHIdBBM7tVnot0aaRhI5qwSOWpzyvJCkYa4eqPgqlV4XYVMqE3zeB/Cx4C9bv4poMXnaGlfFPdkhMYbUcdtsw4gBXXhqUx//9x7eu9cOERRzLquM8Z8rewRpar/kkVKSCV6h8pX19kRj+KEkK5LZB8IUIG995g1lsVFOqdO4mVFBJ1wZCkwJczgVI+jdNGgnR2lpdjwIpJFm+5Hm0y9SwR0UFvgkm95NrmY+Sruty/Zf8ekQwF4+atubW8CE6i8wm2zZpMEnnfS4WFwAwg==",
|
|
appId: "wx8fc3e4305d2fbf0b",
|
|
signType: "RSA",
|
|
nonceStr: "DxpF2uIMl0VM7vPOG7pWnPHk2Dvi3V7K"
|
|
});
|
|
function callWeixinPay(data) {
|
|
const invokePay = () => {
|
|
window.WeixinJSBridge.invoke(
|
|
"getBrandWCPayRequest",
|
|
{
|
|
appId: data.appId,
|
|
timeStamp: data.timeStamp,
|
|
nonceStr: data.nonceStr,
|
|
package: data.package,
|
|
signType: data.signType,
|
|
paySign: data.paySign
|
|
},
|
|
function(res) {
|
|
loading.value = false;
|
|
if (res.err_msg === "get_brand_wcpay_request:ok") {
|
|
statusMessage.value = "支付成功";
|
|
} else {
|
|
statusMessage.value = "支付失败或取消";
|
|
}
|
|
}
|
|
);
|
|
};
|
|
if (typeof window.WeixinJSBridge === "undefined") {
|
|
document.addEventListener("WeixinJSBridgeReady", invokePay, false);
|
|
} else {
|
|
invokePay();
|
|
}
|
|
}
|
|
const diaoqu = () => {
|
|
const urlpost = `https://www.focusnu.com/nursing-unit_0010507/weiXinPay/native`;
|
|
const payload = {
|
|
title: "测试订单",
|
|
openId: openid.value,
|
|
amountPrice: amount.value,
|
|
orgCode: "组织id",
|
|
nursingUnit: "护理单元id",
|
|
customerId: "顾客id",
|
|
orderType: "订单类型",
|
|
price: 1,
|
|
count: 1,
|
|
unit: "单位"
|
|
};
|
|
common_vendor.index.__f__("log", "at pages/pay/index.vue:77", "???/", payload);
|
|
fetch(urlpost, {
|
|
method: "POST",
|
|
headers: {
|
|
"Content-Type": "application/json"
|
|
},
|
|
body: JSON.stringify(payload)
|
|
}).then((res) => res.json()).then((data) => {
|
|
if (data.appId) {
|
|
callWeixinPay(data);
|
|
} else {
|
|
common_vendor.index.showToast({
|
|
title: "支付失败",
|
|
icon: "error"
|
|
});
|
|
}
|
|
}).catch((err) => {
|
|
common_vendor.index.__f__("error", "at pages/pay/index.vue:97", "请求失败:", err);
|
|
});
|
|
};
|
|
const saveurl = common_vendor.ref("");
|
|
const openid = common_vendor.ref("");
|
|
function initiatePayment() {
|
|
if (!amount.value)
|
|
return;
|
|
loading.value = true;
|
|
statusMessage.value = "拉起微信支付...";
|
|
common_vendor.index.getStorage({
|
|
key: "serverUrl",
|
|
success: function(res) {
|
|
common_vendor.index.__f__("log", "at pages/pay/index.vue:109", "读取缓存:", res.data.url);
|
|
saveurl.value = res.data.url;
|
|
}
|
|
});
|
|
common_vendor.index.getStorage({
|
|
key: "openid",
|
|
success: function(res) {
|
|
common_vendor.index.__f__("log", "at pages/pay/index.vue:117", "读取缓存:", res.data.openid);
|
|
openid.value = res.data.openid;
|
|
}
|
|
});
|
|
diaoqu();
|
|
}
|
|
return (_ctx, _cache) => {
|
|
return common_vendor.e({
|
|
a: amount.value,
|
|
b: common_vendor.o(($event) => amount.value = $event.detail.value),
|
|
c: common_vendor.o(initiatePayment),
|
|
d: loading.value || !amount.value,
|
|
e: statusMessage.value
|
|
}, statusMessage.value ? {
|
|
f: common_vendor.t(statusMessage.value)
|
|
} : {});
|
|
};
|
|
}
|
|
};
|
|
const MiniProgramPage = /* @__PURE__ */ common_vendor._export_sfc(_sfc_main, [["__scopeId", "data-v-d7fd7b38"]]);
|
|
wx.createPage(MiniProgramPage);
|
|
//# sourceMappingURL=../../../.sourcemap/mp-weixin/pages/pay/index.js.map
|