(轉)微信公眾平台開發 - WeixinJSBridge API (微信內置瀏覽器私有接口)


來源:http://www.oschina.net/code/snippet_1399261_37142

@{
    Layout = "~/Views/Shared/_Layout_WeUI.cshtml";
}
<style>
    a {
        color: #fff;
        text-shadow: none;
        margin: 10px;
    }
</style>
<div>
    <a class="weui-btn weui-btn_primary" id="imagePreview">圖片預覽</a>
    <a class="weui-btn weui-btn_primary" id="profile">查看profile</a>
    <a class="weui-btn weui-btn_primary" href="weixin://profile/gh_412d74fbb474">企業微信小助手</a>
    <a class="weui-btn weui-btn_primary" id="shareWeibo">分享微博</a>
    <a class="weui-btn weui-btn_primary" id="shareFB">分享facebook</a>
    <a class="weui-btn weui-btn_primary" id="addContact">添加聯系人</a>
    <a class="weui-btn weui-btn_primary" id="scanQRCode">掃描二維碼</a>
    <a class="weui-btn weui-btn_primary" id="jumpToBizProfile">跳轉到指定公眾賬號頁面</a>
    <a class="weui-btn weui-btn_primary" id="toggleMenuBtn">隱藏右上角按鈕</a>
    <a class="weui-btn weui-btn_primary" id="toggleToolbar">隱藏底部導航欄</a>
    <a class="weui-btn weui-btn_primary" id="getNetType">獲取網絡狀態</a>
    <a class="weui-btn weui-btn_primary" id="closeWindow">關閉</a>
    <a class="weui-btn weui-btn_primary" id="getBrandWCPayRequest">發起公眾號微信支付</a>
    <a class="weui-btn weui-btn_primary" id="setPageState">設置頁面狀態</a>
    <a class="weui-btn weui-btn_primary" id="sendEmail">發郵件</a>
    <a class="weui-btn weui-btn_primary" id="openSpecificView">微信團隊打開webView,跳到指定頁面</a>
    <a class="weui-btn weui-btn_primary" id="getCanIAPPay">getCanIAPPay</a>
    <a class="weui-btn weui-btn_primary" id="getBrandIAPPayRequest">發起公眾號IAP支付</a>
    <a class="weui-btn weui-btn_primary" id="openUrlByExtBrowser">用safari打開指定鏈接</a>
    <a class="weui-btn weui-btn_primary" id="openProductView">跳轉微信商品頁</a>
    <a class="weui-btn weui-btn_primary" id="openLocation">查看地理位置</a>
    <a class="weui-btn weui-btn_primary" id="timelineCheckIn">朋友圈簽到</a>
    <a class="weui-btn weui-btn_primary" id="getBrandWCPayCreateCreditCardRequest">開通微信信用卡</a>
    <a class="weui-btn weui-btn_primary" id="geoLocation">獲取地理位置</a>
    <a class="weui-btn weui-btn_primary" id="getInstallState">獲取某app是否安裝</a>
    <a class="weui-btn weui-btn_primary" id="editAddress">公眾號編輯收貨地址</a>
    <a class="weui-btn weui-btn_primary" id="getLatestAddress">公眾號獲取最近的收貨地址</a>
    <a class="weui-btn weui-btn_primary" id="launch3rdApp">啟動第三方APP</a>
    <a class="weui-btn weui-btn_primary" id="jumpWCMall">跳轉微信商品購買界面</a>
    <a class="weui-btn weui-btn_primary" id="addEmoticon">添加表情</a>
    <a class="weui-btn weui-btn_primary" id="cancelAddEmoticon">取消下載某表情</a>
    <a class="weui-btn weui-btn_primary" id="hasEmoticon">查詢是否存在某表情</a>
</div>

<script>
    function onBridgeReady() {
        WeixinJSBridge.on('menu:share:appmessage', function (argv) {
            WeixinJSBridge.invoke('sendAppMessage', {
                "link": "http://m.exmail.qq.com/",
                "desc": "desc",
                "title": "title for WeiXinJsBridge"
            }, function (res) {
                WeixinJSBridge.log(res.err_msg);
            });
        });
        WeixinJSBridge.on('menu:share:timeline', function (argv) {
            WeixinJSBridge.invoke("shareTimeline", {
                "link": "http://m.exmail.qq.com",
                "img_url": "http://rescdn.qqmail.com/bizmail/zh_CN/htmledition/images/bizmail/v3/logo1ca3fe.png",
                "img_width": "172",
                "img_height": "40",
                "desc": "i am description",
                "title": "just test from WeixinJsBridge"
            },
            function (e) {
                alert(e.err_msg);
            })
        });
    }

    if (typeof WeixinJSBridge === "undefined") {
        if (document.addEventListener) {
            document.addEventListener("WeixinJSBridgeReady", onBridgeReady, false);
        }
    } else {
        onBridgeReady();
    }

    var menuHidden = !1, toolbarHidden = !1, netType = { "network_type:wifi": "wifi網絡", "network_type:edge": "非wifi,包含3G/2G", "network_type:fail": "網絡斷開連接", "network_type:wwan": "2g或者3g" };
    document.addEventListener("WeixinJSBridgeReady", function () {
        document.getElementById("imagePreview").addEventListener("click", function () {
            WeixinJSBridge.invoke("imagePreview", {
                "urls": [
                    "http://rescdn.qqmail.com/bizmail/zh_CN/htmledition/images/bizmail/v3/logo1ca3fe.png",
                    "http://rescdn.qqmail.com/bizmail/zh_CN/htmledition/images/bizmail/v3/icons_features1ca3fe.png",
                    "http://rescdn.qqmail.com/bizmail/zh_CN/htmledition/images/bizmail/v3/icons_workStyle1ca3fe.png"
                ],
                "current": "http://rescdn.qqmail.com/bizmail/zh_CN/htmledition/images/bizmail/v3/icons_features1ca3fe.png"
            })
        }, !1),
        document.getElementById("profile").addEventListener("click", function () {
            alert("profile clicked");
            WeixinJSBridge.invoke("profile", {
                "username": "gh_412d74fbb474",
                "nickname": "企業微信小助手"
            })
        }, !1),
        document.getElementById("shareWeibo").addEventListener("click", function () {
            WeixinJSBridge.invoke("shareWeibo", {
                "type": "link",
                "link": "http://m.exmail.qq.com"
            },
            function (e) {
                alert(e.err_msg);
            })
        }, !1),
        document.getElementById("shareFB").addEventListener("click", function () {
            WeixinJSBridge.invoke("shareFB", {
                "link": "http://m.exmail.qq.com"
            })
        }, !1),

        document.getElementById("scanQRCode").addEventListener("click", function () {
            WeixinJSBridge.invoke("scanQRCode", {
            })
        }, !1),
        document.getElementById("addEmoticon").addEventListener("click", function () {
            WeixinJSBridge.invoke("addEmoticon", {
                "url": "http://rescdn.qqmail.com/bizmail/zh_CN/htmledition/images/bizmail/v3/icons_features1ca3fe.png",
                "thumb_url": "http://rescdn.qqmail.com/bizmail/zh_CN/htmledition/images/bizmail/v3/logo1ca3fe.png"

            },
            function (e) {
                alert(e.err_msg);
            })
        }, !1),
        document.getElementById("cancelAddEmoticon").addEventListener("click", function () {
            WeixinJSBridge.invoke("cancelAddEmoticon", {
                "url": "http://rescdn.qqmail.com/bizmail/zh_CN/htmledition/images/bizmail/v3/icons_features1ca3fe.png"

            },
            function (e) {
                alert(e.err_msg);
            })
        }, !1),
        document.getElementById("hasEmoticon").addEventListener("click", function () {
            WeixinJSBridge.invoke("hasEmoticon", {
                "url": "http://rescdn.qqmail.com/bizmail/zh_CN/htmledition/images/bizmail/v3/icons_features1ca3fe.png"

            },
            function (e) {
                alert(e.err_msg);
            })
        }, !1),
        document.getElementById("addContact").addEventListener("click", function () {
            WeixinJSBridge.invoke("addContact", {
                "webtype": "1",
                "username": "gh_412d74fbb474"
            },
            function (e) {
                alert(e.err_msg);
            })
        }, !1),
        document.getElementById("jumpToBizProfile").addEventListener("click", function () {
            WeixinJSBridge.invoke("jumpToBizProfile", {
                "tousername": "gh_2248a2ade13e"
            },
            function (e) {
                alert(e.err_msg);
            })
        }, !1),
        document.getElementById("toggleMenuBtn").addEventListener("click", function () {
            menuHidden ?
            (WeixinJSBridge.call("showOptionMenu"), menuHidden = !1, this.value = "隱藏右上角按鈕")
            :
            (WeixinJSBridge.call("hideOptionMenu"), menuHidden = !0, this.value = "顯示右上角按鈕")
        }, !1),
        document.getElementById("toggleToolbar").addEventListener("click", function () {
            toolbarHidden ?
            (WeixinJSBridge.call("showToolbar"), toolbarHidden = !1, this.value = "隱藏底部導航欄")
            :
            (WeixinJSBridge.call("hideToolbar"), toolbarHidden = !0, this.value = "顯示底部導航欄")
        }, !1),
        document.getElementById("getNetType").addEventListener("click", function () {
            WeixinJSBridge.invoke("getNetworkType", {},
                function (e) {
                    alert(netType[e.err_msg])
                })
        }, !1),
        document.getElementById("closeWindow").addEventListener("click", function () {
            WeixinJSBridge.invoke("closeWindow", {}, function (e) { })
        }, !1),
        document.getElementById("getBrandWCPayRequest").addEventListener("click", function () {
            WeixinJSBridge.invoke("getBrandWCPayRequest", {
                "appId": "wxf8b4f85f3a794e77", //公眾號名稱,由商戶傳入
                "timeStamp": "189026618", //時間戳 這里隨意使用了一個值
                "nonceStr": "adssdasssd13d", //隨機串
                "package": "body=xxx&fee_type=1&input_charset=GBK¬ify_url=http&out_trade_no=16642817866003386000&partner=1900000109&return_url=http&spbill_create_ip=127.0.0.1&total_fee=1&sign=273B7EEEE642A8E41F27213D8517E0E4", //擴展字段,由商戶傳入
                "signType": "SHA1", //微信簽名⽅方式:sha1
                "paySign": "b737015b5b1eabe5db580945a07eac08c7bb55f8" //微信簽名
            },
            function (e) {
                alert(e.err_msg)
            })
        }, !1),
        document.getElementById("setPageState").addEventListener("click", function () {
            WeixinJSBridge.invoke("setPageState", {
                "state": "1"
            })
        }, !1),

        document.getElementById("sendEmail").addEventListener("click", function () {
            WeixinJSBridge.invoke("sendEmail", {
                "title": "title!",
                "content": "i am an Email!", //時間戳 這⾥里隨意使⽤用了⼀一個值
            },
                function (e) {
                    //alert(e.err_msg)
                })
        }, !1),
        document.getElementById("openSpecificView").addEventListener("click", function () {
            WeixinJSBridge.invoke("openSpecificView", {
                "specificview": "contacts"
            },
                function (e) {
                    alert(e.err_msg)
                })
        }, !1),
        document.getElementById("getCanIAPPay").addEventListener("click", function () {
            WeixinJSBridge.invoke("getCanIAPPay", {},
                function (e) {
                    alert(e.err_msg)
                })
        }, !1),
        document.getElementById("getBrandIAPPayRequest").addEventListener("click", function () {
            WeixinJSBridge.invoke("getBrandIAPPayRequest", {
                "appId": "wxf8b4f85f3a794e77", //公眾號名稱,由商戶傳入
                "timeStamp": "189026618", //時間戳 這里隨意使⽤用了一個值
                "nonceStr": "adssdasssd13d", //隨機串
                "package": "bankType=CITIC_CREDIT&bankName=%e4%b8%ad%e4%bf%a1%e9%93%b6%e8%a1%8c&sign=CF8922F49431FFE8A1834D0B32B25CE3",
                //擴展字段,由商戶傳入
                "signType": "SHA1", //微信簽名⽅方式:sha1
                "paySign": "1e6f13f78ca0ec43fbb80899087f77568af66987" //微信簽名
            },
                function (e) {
                    alert(e.err_msg)
                })
        }, !1),
        document.getElementById("openLocation").addEventListener("click", function () {
            WeixinJSBridge.invoke("openProductView", {
                "latitude": 23.113, //緯度
                "longitude": 113.23, //經度
                "name": "TIT創意園", //POI名稱
                "address": "⼲⼴廣州市海珠區新港中路397號", //地址
                "scale": 14, //地圖縮放級別
                "infoUrl": "http://weixin.qq.com/", //查看位置界⾯面底部的超鏈接                
            },
                function (e) {
                    alert(e.err_msg)
                })
        }, !1),
        document.getElementById("timelineCheckIn").addEventListener("click", function () {
            WeixinJSBridge.invoke("timelineCheckIn", {
                "img_url": "http://mmsns.qpic.cn/mmsns/RLllkTm3DUdV24xbZnKicx9jJWxXI0Bq84zzbtibGuRyk/0", // 分享到朋友圈的縮略圖
                "img_width": "640", // 圖⽚片的⻓長度
                "img_height": "640", // 圖⽚片⾼高度
                "link": "http://news.qq.com/zt2012/cxkyym/index.htm", // 連接地址
                "desc": "這個是描述啊啊", // 描述
                "title": "朝鮮稱中國漁船越界捕撈", // 分享標題
                "latitude": 23.113, //緯度
                "longitude": 113.23, //經度
                "poiId": "dianping_2331037", //商戶id
                "poiName": "TIT創意園", //POI名稱
                "poiAddress": "⼲⼴廣州市海珠區新港中路397號", //地址
                "poiScale": 14, //地圖縮放級別
                "poiInfoUrl": "http://weixin.qq.com/" //查看位置界⾯面底部的超鏈接
            },
                function (e) {
                    alert(e.err_msg)
                })
        }, !1),
        document.getElementById("geoLocation").addEventListener("click", function () {
            WeixinJSBridge.invoke("geoLocation", {
            },
                function (e) {
                    alert(e.err_msg)
                })
        }, !1),
        document.getElementById("getBrandWCPayCreateCreditCardRequest").addEventListener("click", function () {
            WeixinJSBridge.invoke("getBrandWCPayCreateCreditCardRequest", {
                "appId": "wxf8b4f85f3a794e77", //公眾號名稱,由商戶傳入
                "timeStamp": "189026618", //時間戳 這里隨意使用了一個值
                "nonceStr": "adssdasssd13d", //隨機串
                "package": "bankType=CITIC_CREDIT&bankName=%e4%b8%ad%e4%bf%a1%e9%93%b6%e8%a1%8c&sign= CF8922F49431FFE8A1834D0B32B25CE3",
                //擴展字段,由商戶傳入
                "signType": "SHA1", //微信簽名⽅方式:sha1
                "paySign": "1e6f13f78ca0ec43fbb80899087f77568af66987" //微信簽名
            },
                function (e) {
                    alert(e.err_msg)
                })
        }, !1),
        document.getElementById("getInstallState").addEventListener("click", function () {
            WeixinJSBridge.invoke("getInstallState", {
                "packageUrl": "teamcircle://"
            },
                function (e) {
                    alert(e.err_msg)
                })
        }, !1),
        document.getElementById("openProductView").addEventListener("click", function () {
            WeixinJSBridge.invoke("openProductView", {
                "productInfo": "json"
            },
                function (e) {
                    alert(e.err_msg)
                })
        }, !1),
        document.getElementById("getLatestAddress").addEventListener("click", function () {
            WeixinJSBridge.invoke("getLatestAddress", {
                "appId": "wxf8b4f85f3a794e77", //公眾號名稱,由商戶傳入
                "timeStamp": "189026618", //時間戳 這里隨意使用了一個值
                "nonceStr": "adssdasssd13d", //隨機串
                "signType": "SHA1", //微信簽名⽅方式:sha1
                "addrSign": "b737015b5b1eabe5db580945a07eac08c7bb55f8", //微信簽名
                "scope": "snsapi"
            },
            function (e) {
                alert(e.err_msg)
            })
        }, !1),
        document.getElementById("editAddress").addEventListener("click", function () {
            WeixinJSBridge.invoke("editAddress", {
                "appId": "wxf8b4f85f3a794e77", //公眾號名稱,由商戶傳入
                "timeStamp": "189026618", //時間戳 這里隨意使用了一個值
                "nonceStr": "adssdasssd13d", //隨機串
                "signType": "SHA1", //微信簽名⽅方式:sha1
                "addrSign": "b737015b5b1eabe5db580945a07eac08c7bb55f8", //微信簽名
                "scope": "snsapi"
            },
            function (e) {
                alert(e.err_msg)
            })
        }, !1),
        document.getElementById("launch3rdApp").addEventListener("click", function () {
            WeixinJSBridge.invoke("launch3rdApp", {
                "appId": "wx5823bf96d3bd56c7", //公眾號名稱,由商戶傳入
            },
            function (e) {
                alert(e.err_msg)
            })
        }, !1),
        document.getElementById("jumpWCMall").addEventListener("click", function () {
            WeixinJSBridge.invoke("jumpWCMall", {
                "appId": "wx5823bf96d3bd56c7", //公眾號名稱,由商戶傳入
                "funcId": "1000"
            },
            function (e) {
                alert(e.err_msg)
            })
        }, !1),
        document.getElementById("openUrlByExtBrowser").addEventListener("click", function () {
            WeixinJSBridge.invoke("openUrlByExtBrowser", {
                "url": "http://m.exmail.qq.com"
            },
                function (e) {
                    alert(e.err_msg)
                })
        }, !1)
    });
</script>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM