微信调用APP接口

来源:互联网 发布:黑蚂蚁网络电视安卓版 编辑:程序博客网 时间:2024/04/30 13:53
(function (w,d) {
if (!window.rBridge) {
window.rBridge = {};
}
    var isJSBridge = false;
    function connectJSBridge(callback) {
        if (w.JSBridge) {
            isJSBridge = true;
            callback(JSBridge);
        } else {
            d.addEventListener('JSBridgeReady', function() {
                isJSBridge = true;
                callback(JSBridge);
            }, false);
        }
    }
    rBridge = {
        version : '1.0',
        isJSBridge:function(){
            return isJSBridge;
        },
        callback:function(e){
        },
init:function(){
            var _self = this;


            connectJSBridge(function(bridge) {
                bridge.init(function(message, responseCallback) {
                    var data = { 'Javascript Responds':'Wee!' };
                    bridge.callEventCallback(responseCallback,data,message);
                });
                var apiList ={
                    loadDetail:function(e){
                        if(isJSBridge){
                            JSBridge.callAPI("NativeDetail", e.data);
                            return true;
                        } else {
                            return false;
                        }
                    },
                    loadTalent:function(e){
                        if(isJSBridge){
                            JSBridge.callAPI("NativeTalent", e.data);
                            return true;
                        } else {
                            return false;
                        }
                    },
                    login:function(e){
                        if(isJSBridge){
                            JSBridge.callAPI("NativeLogin");
                            return true;
                        }else{
                            return false;
                        }
                    },
                    register:function(e){
                        if(isJSBridge){
                            JSBridge.callAPI("NativeRegister");
                            return true;
                        }else{
                            return false;
                        }
                    },
                    getToken:function(e){
                        if(isJSBridge){
                            return JSBridge.callAPI("NativeGetTokenSync");
                        }else{
                            return "";
                        }
                    },
                    /**
                     * App分享页面
                     * @param e
                     * @returns {*}
                     */
                    share:function(e){
                        if(isJSBridge){
                            try{
                                JSBridge.registerHandler("functionInShare", function(data, responseCallback) {
                                    var responseData = e.data;
                                    responseCallback(responseData);
                                });
                            }catch(ee){
                                return false;
                            }
                            return true;
                        }else{
                            return false;
                        }
                    },
                    Index:function(e){
                        if(isJSBridge){
                            return JSBridge.callAPI("NativeIndex");
                        }else{
                            return "";
                        }
                    }
                };
                _self.callback(apiList);
            });
            return true;
}
};
    rBridge.init();

})(window,document);




调用:

var bridgeObj;
    rscBridge.callback = function(appB) {
bridgeObj= appB;
        bridgeObj.share({data: {imgUrl: $("#avatar").val(), link: window.location.href}});
    }

0 0
原创粉丝点击