vue history模式下的微信支付,及微信支付授权目录的填写,处理URL未注册

微信公众号配置网页授权域名:填写网址域名

微信开发者平台配置url:

访问url:http://www.baidu.com/pay/ment
支付授权目录:http://www.baidu.com/pay/

访问url:http://www.baidu.com/pay
支付授权目录:http://www.baidu.com/

访问url:http://www.baidu.com/pay/ment?id=123
支付授权目录:http://www.baidu.com/pay/

 / 记得加上

 

下面是微信支付页:

<template>
  <div id='wxPay'>
  </div>
</template>

<script>
export default {
  data () {
    return {
      name: '微信支付页',
      router: 'wxPay',
      payJson: {}
    }
  },
  methods: {
    get_jsapi_ticket () {
      let payJson = eval('(' + this.payJson + ')') // eslint-disable-line
      console.log(payJson)
      this.api.get_jsapi_ticket({ url: window.location.href }).then(res => {
        wx.config({ // eslint-disable-line
          debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
          appId: res.data.appId, // 必填,公众号的唯一标识
          timestamp: res.data.timestamp, // 必填,生成签名的时间戳
          nonceStr: res.data.nonceStr, // 必填,生成签名的随机串
          signature: res.data.signature, // 必填,签名
          jsApiList: ['chooseWXPay'] // 必填,需要使用的JS接口列表
        })
        wx.ready(() => { // eslint-disable-line
          wx.chooseWXPay({ // eslint-disable-line
            timestamp: payJson.timeStamp, // 支付签名时间戳,注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
            nonceStr: payJson.nonceStr, // 支付签名随机串,不长于 32 位
            package: payJson.package, // 统一支付接口返回的prepay_id参数值,提交格式如:prepay_id=***)
            signType: payJson.signType, // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
            paySign: payJson.paySign, // 支付签名
            success: function (res) {
              // 支付成功后的回调函数
              this.$router.push('/myIndex')
            },
            fail: function (res) {
              // 失败回调函数
              this.$router.push('/myIndex')
            }
          })
        })
        wx.error(err => { // eslint-disable-line
          alert(err)
        })
      })
    }
  },
  created () {
    document.title = '支付中'
    this.payJson = decodeURIComponent(this.$route.query.payJson)
    this.get_jsapi_ticket()
  }
}
</script>

  有问题可以加我QQ:412606846(微信同号)

转载于:https://www.cnblogs.com/zlfProgrammer/p/11585663.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
首先,你需要安装Vue.js和Vue CLI。在安装完成后,你可以使用Vue CLI创建一个新的Vue项目: ```bash vue create my-chat-app ``` 然后,在你的项目目录中,你可以创建一个名为`Chat.vue`的组件,这个组件将会显示聊天界面。在这个组件中,你可以使用Vue的数据绑定功能来绑定聊天记录和输入框的值。 ```vue <template> <div class="chat"> <div class="chat-history"> <div class="message" v-for="(message, index) in messages" :key="index"> <div class="message-content">{{ message.content }}</div> <div class="message-time">{{ message.time }}</div> </div> </div> <div class="chat-input"> <input type="text" v-model="inputMessage" @keyup.enter="sendMessage"> <button @click="sendMessage">Send</button> </div> </div> </template> <script> export default { data() { return { messages: [], inputMessage: "", }; }, methods: { sendMessage() { const time = new Date().toLocaleTimeString(); const content = this.inputMessage; this.messages.push({ content, time }); this.inputMessage = ""; }, }, }; </script> ``` 在这个组件中,我们有一个`messages`数组,它将会存储聊天记录。我们还有一个`inputMessage`变量,用来存储用户输入的内容。在`sendMessage`方法中,我们将用户输入的内容添加到`messages`数组中,并清空输入框的值。 接下来,你可以在你的应用程序中使用这个组件来显示聊天界面。 ```vue <template> <div class="app"> <chat></chat> </div> </template> <script> import Chat from "./components/Chat.vue"; export default { components: { Chat, }, }; </script> ``` 最后,你可以使用CSS样式来美化你的聊天界面。 ```css .chat { display: flex; flex-direction: column; height: 100%; } .chat-history { flex: 1; overflow: auto; } .message { display: flex; flex-direction: column; margin: 10px; } .message-content { background-color: #eee; padding: 10px; border-radius: 10px; max-width: 60%; } .message-time { font-size: 12px; text-align: right; } .chat-input { display: flex; align-items: center; } .chat-input input[type="text"] { flex: 1; height: 30px; margin-right: 10px; border-radius: 5px; border: none; padding: 5px; } .chat-input button { background-color: #4caf50; color: #fff; border: none; border-radius: 5px; padding: 5px 10px; } ``` 以上是一个简单的Vue.js微信聊天界面的开发过程,你可以根据你的需求进行相应的修改和扩展。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值