• 隐藏微信网页右上角的按钮、在微信网页中获取用户的网络状态,支付等


    1.隐藏微信网页右上角按钮
    <script type="text/javascript">
    	document.addEventListener('WeixinJSBridgeReady',function onBridgeReady() {
        	// 通过下面这个API隐藏右上角按钮
        	WeixinJSBridge.call('hideOptionMenu');
    });
    	document.addEventListener('WeixinJSBridgeReady',function onBridgeReady() {
       		 // 通过下面这个API显示右上角按钮`
        	WeixinJSBridge.call('showOptionMenu');
    });
    </script>
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    2.在微信网页中获取用户的网络状态
    WeixinJSBridge.invoke('getNetworkType',{},function (e){
        // 在这里拿到e.err_msg,这里面就包含了所有的网络类型
        alert(e.err_msg);
    });
    
    //e.err_msg的取值如下所示:
    
    //network_type:wifi         wifi网络
    //network_type:edge      非wifi,包含3G/2G
    //network_type:fail         网络断开连接
    //network_type:wwan     2g或者3g
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    3.在微信网页中支付
    function onBridgeReady(orderId, response) {
          WeixinJSBridge.invoke(
            "getBrandWCPayRequest",
            {
              appId: response.appId, //公众号ID,由商户传入
              timeStamp: response.timeStamp, //时间戳,自1970年以来的秒数
              nonceStr: response.nonceStr, //随机串
              package: response.packageVal,
              signType: response.signType, //微信签名方式:
              paySign: response.paySign //微信签名
            },
            function (res) {
              // 使用以上方式判断前端返回,微信团队郑重提示:
              //res.err_msg将在用户支付成功后返回ok,但并不保证它绝对可靠。
              if (res.err_msg == "get_brand_wcpay_request:ok") {
                $api.pay_order(orderId).then(res => {
                  if (res.code == 1) {
                    state.assistOne = false;
                    state.assistTwo = false;
                    $Toast({
                      duration: 3000,
                      message: "支付成功!"
                    });
                    emit("get_brand_wcpay");
                  }
                });
              }
              // 支付过程中用户取消
              if (res.err_msg == "get_brand_wcpay_request:cancel") {
              }
              // 支付失败
              if (res.err_msg == "get_brand_wcpay_request:fail") {
              }
              /**
               * 其它
               * 1、请检查预支付会话标识prepay_id是否已失效
               * 2、请求的appid与下单接口的appid是否一致
               * */
              if (res.err_msg == "调用支付JSAPI缺少参数:total_fee") {
              }
            }
          );
        }
        if (typeof WeixinJSBridge == "undefined") {
          if (document.addEventListener) {
            document.addEventListener("WeixinJSBridgeReady", onBridgeReady, false);
          } else if (document.attachEvent) {
            document.attachEvent("WeixinJSBridgeReady", onBridgeReady);
            document.attachEvent("onWeixinJSBridgeReady", onBridgeReady);
          }
        } else {
          onBridgeReady();
        }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
    • 33
    • 34
    • 35
    • 36
    • 37
    • 38
    • 39
    • 40
    • 41
    • 42
    • 43
    • 44
    • 45
    • 46
    • 47
    • 48
    • 49
    • 50
    • 51
    • 52
    • 53
  • 相关阅读:
    TiDB 7.1.0 LTS 特性解读丨关于资源管控 (Resource Control) 应该知道的 6 件事
    shell编程必备100题
    创业合伙必读之:合伙企业登记指南
    认识100种电路之振荡电路
    [附源码]SSM计算机毕业设计成都团结石材城商家协作系统JAVA
    Two-Stream Consensus Network论文阅读
    数据中心电力供应,请掌握这个技能!
    字符串左旋解法和子字符串判断法
    新增文章出现bug怎么定位是前端问题还是后端问题
    面试题:深拷贝方法、for in 和for of区别 、this指向、改变this指向
  • 原文地址:https://blog.csdn.net/weixin_49295874/article/details/134012910