|
@@ -16,33 +16,39 @@
|
|
|
</div>
|
|
|
</div>
|
|
|
<div class="pay_area">
|
|
|
- <div class="pay_btn" @click="jsSdk()">立即购买</div>
|
|
|
+ <div class="pay_btn" @click="pay">立即购买</div>
|
|
|
<div style="display: flex; justify-content: center">
|
|
|
<!-- <el-checkbox
|
|
|
v-model="checked"
|
|
|
@change="checkboxChange"
|
|
|
style="margin-top: 2px"
|
|
|
/> -->
|
|
|
- <div class="xy" @click="goXy()">点击购买即代表同意<span style="color:rgba(20,80,130);font-weight:900;">《平台用户服务协议》</span></div>
|
|
|
+ <div class="xy" @click="goXy()">
|
|
|
+ 点击购买即代表同意<span
|
|
|
+ style="color: rgba(20, 80, 130); font-weight: 900"
|
|
|
+ >《平台用户服务协议》</span
|
|
|
+ >
|
|
|
+ </div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</div>
|
|
|
</template>
|
|
|
<script>
|
|
|
import openId from "../util/getOpenId";
|
|
|
+import { Message } from "element-ui";
|
|
|
+import { getPay, getPayList, getMypayList } from "../api";
|
|
|
export default {
|
|
|
name: "index",
|
|
|
data() {
|
|
|
return {
|
|
|
- url: require("../assets/huiyuan_bj.png"),
|
|
|
+ url: require("../assets/huiyuan_bj.jpg"),
|
|
|
radioTreaty: "1",
|
|
|
- // checked: false,
|
|
|
- payOption: {
|
|
|
- appId: "wxeef6678b92b6c856", //公众号名称,由商户传入
|
|
|
+ payOptions: {
|
|
|
+ appId: "", //公众号名称,由商户传入
|
|
|
timeStamp: "", //时间戳,自1970年以来的秒数
|
|
|
nonceStr: "", //随机串
|
|
|
- package: "prepay_id=wxXXXXXXX", //prepay_id用等式的格式
|
|
|
- signType: "MD5", //微信签名方式:
|
|
|
+ package: "", //prepay_id用等式的格式
|
|
|
+ signType: "", //微信签名方式:
|
|
|
paySign: "", //微信签名
|
|
|
},
|
|
|
};
|
|
@@ -63,27 +69,13 @@ export default {
|
|
|
radioChange: (val) => {
|
|
|
console.log(val);
|
|
|
},
|
|
|
- checkboxChange: (val) => {
|
|
|
- this.checked = val;
|
|
|
- console.log(val);
|
|
|
- },
|
|
|
- getTimeStamp() {
|
|
|
- this.payOption.timeStamp = new Date().getTime();
|
|
|
- },
|
|
|
- randomString() {
|
|
|
- let len = 32;
|
|
|
- let $chars = "ABCDEFGHJKMNPQRSTWXYZabcdefhijkmnprstwxyz2345678";
|
|
|
- let maxPos = $chars.length;
|
|
|
- let pwd = "";
|
|
|
- for (let i = 0; i < len; i++) {
|
|
|
- pwd += $chars.charAt(Math.floor(Math.random() * maxPos));
|
|
|
- }
|
|
|
- console.log(pwd);
|
|
|
- this.payOption.nonceStr = pwd;
|
|
|
- },
|
|
|
+ // checkboxChange: (val) => {
|
|
|
+ // this.checked = val;
|
|
|
+ // console.log(this.checked);
|
|
|
+ // },
|
|
|
jsSdk() {
|
|
|
// 判断微信的WeixinJSBridge
|
|
|
- console.log(typeof WeixinJSBridge)
|
|
|
+ console.log(typeof WeixinJSBridge);
|
|
|
if (typeof WeixinJSBridge == "undefined") {
|
|
|
if (document.addEventListener) {
|
|
|
document.addEventListener(
|
|
@@ -96,10 +88,7 @@ export default {
|
|
|
document.attachEvent("onWeixinJSBridgeReady", this.onBridgeReady);
|
|
|
}
|
|
|
} else {
|
|
|
- // this.randomString();
|
|
|
- // this.getTimeStamp();
|
|
|
this.onBridgeReady();
|
|
|
-
|
|
|
}
|
|
|
},
|
|
|
// 支付sdk准备完成
|
|
@@ -107,35 +96,82 @@ export default {
|
|
|
// 触发微信支付
|
|
|
WeixinJSBridge.invoke(
|
|
|
"getBrandWCPayRequest",
|
|
|
- {
|
|
|
- appId: this.payOption.appId, //公众号名称,由商户传入
|
|
|
- timeStamp: this.payOption.timeStamp, //时间戳,自1970年以来的秒数
|
|
|
- nonceStr: this.payOption.nonceStr, //随机串
|
|
|
- package: this.payOption.package, //prepay_id用等式的格式
|
|
|
- signType: this.payOption.signType, //微信签名方式:
|
|
|
- paySign: this.payOption.paySign, //微信签名
|
|
|
- },
|
|
|
+ this.payOptions,
|
|
|
function (res) {
|
|
|
+ console.log(res);
|
|
|
if (res.err_msg == "get_brand_wcpay_request:ok") {
|
|
|
// 支付成功 返回成功页
|
|
|
- let tempUrl = "//paysucc";
|
|
|
+ let tempUrl = "https://yuehe.hellevil.com/mp/#/paySuccess";
|
|
|
location.href = tempUr;
|
|
|
} else {
|
|
|
// 取消支付或者其他情况 get_brand_wcpay_request:cancel get_brand_wcpay_request:fail
|
|
|
- let tempUrl = "//topay";
|
|
|
+ let tempUrl = "https://yuehe.hellevil.com/mp/#/";
|
|
|
location.href = tempUrl;
|
|
|
}
|
|
|
}
|
|
|
);
|
|
|
},
|
|
|
+ async pay() {
|
|
|
+ let params = {};
|
|
|
+ if (this.radioTreaty == "1") {
|
|
|
+ params = {
|
|
|
+ body: "wxtest199",
|
|
|
+ outTradeNo: new Date().getTime(),
|
|
|
+ totalFee: "1",
|
|
|
+ spbillCreateIp: "127.0.0.1",
|
|
|
+ notifyUrl: "https://yuehe.hellevil.com/pay/notify/order",
|
|
|
+ tradeType: "JSAPI",
|
|
|
+ openid: "oyp646XW37eIqrv3XisVWQ3xq3BQ",
|
|
|
+ // openid: window.localStorage.getItem("openId"),
|
|
|
+ };
|
|
|
+ }
|
|
|
+ if (this.radioTreaty == "2") {
|
|
|
+ params = {
|
|
|
+ body: "wxtest399",
|
|
|
+ outTradeNo: new Date().getTime(),
|
|
|
+ totalFee: "2",
|
|
|
+ spbillCreateIp: "127.0.0.1",
|
|
|
+ notifyUrl: "https://yuehe.hellevil.com/pay/notify/order",
|
|
|
+ tradeType: "JSAPI",
|
|
|
+ openid: "oyp646XW37eIqrv3XisVWQ3xq3BQ",
|
|
|
+ // openid: window.localStorage.getItem("openId"),
|
|
|
+ };
|
|
|
+ }
|
|
|
+ if (this.radioTreaty == "3") {
|
|
|
+ params = {
|
|
|
+ body: "wxtest1999",
|
|
|
+ outTradeNo: new Date().getTime(),
|
|
|
+ totalFee: "3",
|
|
|
+ spbillCreateIp: "127.0.0.1",
|
|
|
+ notifyUrl: "https://yuehe.hellevil.com/pay/notify/order",
|
|
|
+ tradeType: "JSAPI",
|
|
|
+ openid: "oyp646XW37eIqrv3XisVWQ3xq3BQ",
|
|
|
+ // openid: window.localStorage.getItem("openId"),
|
|
|
+ };
|
|
|
+ }
|
|
|
+ console.log(params);
|
|
|
+ const result = await getPay(params);
|
|
|
+ console.log(result);
|
|
|
+ this.payOptions.appId = result.appId; //公众号名称,由商户传入
|
|
|
+ this.payOptions.timeStamp = result.timeStamp; //时间戳,自1970年以来的秒数
|
|
|
+ this.payOptions.nonceStr = result.nonceStr; //随机串
|
|
|
+ this.payOptions.package = result.packageValue; //prepay_id用等式的格式
|
|
|
+ this.payOptions.signType = result.signType; //微信签名方式:
|
|
|
+ this.payOptions.paySign = result.paySign; //微信签
|
|
|
+ console.log(this.payOptions);
|
|
|
+ this.jsSdk();
|
|
|
+ },
|
|
|
},
|
|
|
computed: {},
|
|
|
- mounted() {
|
|
|
+ async mounted() {
|
|
|
// openId.getOpenId(() => {
|
|
|
// let openid = window.localStorage.getItem("openId");
|
|
|
// console.log(openid, "我是获取的openid");
|
|
|
// });
|
|
|
-
|
|
|
+ const result = await getPayList();
|
|
|
+ console.log(result)
|
|
|
+ const result1 = await getMypayList();
|
|
|
+ console.log(result1)
|
|
|
},
|
|
|
};
|
|
|
</script>
|