您当前位置: 首页 > Cocos > 精品代码 > Cocos Creator sdkapi接口js端
Cocos Creator sdkapi接口js端
收藏 报错 好评2

Cocos Creator sdkapi接口js端

10.00 金币

源码类型:精品代码

上传日期:2018-03-27 00:16:21

源码编号:1624

高速下载源码

浏览:450 收藏:1 下载:1

详细介绍

var THIS = null;
/*sdk桥接*/
cc.Class({
    extends: cc.Component,

    properties: {
       
    },
    onLoad(){

        cc.SDKAPI = THIS = this;
        this.ANDROIDAPI = "com/wywl/games/ThirteenYards";
        this.IOSAPI = "AppController";
        /*支付返回*/
        cc.PAYhuidiao = function(data){

            if(data == 1){

                cc.msgbox.show("支付成功");

                if(cc.find("Canvas/zicaidan/qiandao/alert/lunpanan/nengchou")){

                    cc.find("Canvas/zicaidan/qiandao/alert/lunpanan/nengchou").getComponent(cc.Button).interactable = true;
                }

            }else{
                cc.msgbox.show("支付取消");
            }
        }
     
        /*分享返回*/
        cc.Shareback = function(data){

            if(data == 1){

                var myjson = {
                    ac:"POST",
                    y:"duihuan",
                    d:"delete",
                
                    apptoken: cc.userData && cc.userData.data && cc.userData.data.apptoken?cc.userData.data.apptoken:""
                };
            
                cc.HTTP.URL("J",myjson,function(data,status){
        
                    var DATA =  JSON.parse(data);
        
                    
        
                    if(status == '200'){
                        var D = DATA.data;
        
                        if(D.jifen){
                            cc.userData.data.jifen = D.jifen;
                        }
        
                        if(D.huobi){
        
                            cc.userData.data.huobi = D.huobi;
                        }
        
                        if(cc.MAN.binuser){
                            cc.MAN.binuser();
                        }
                    
        
                
        
                    }
                });

                cc.msgbox.show("分享成功");



            }else{
                
                cc.msgbox.show("分享取消");
            }
        }


    },copylink(url){
        /*复制连接
        1
        */

        if(cc.sys.os == cc.sys.OS_ANDROID){
            jsb.reflection.callStaticMethod(this.ANDROIDAPI, "copylink", "(Ljava/lang/String;)V",url);
             

         }else if(cc.sys.os == cc.sys.OS_IOS){
             
             jsb.reflection.callStaticMethod(this.IOSAPI, "copylink:",url);

         }else{


         }

         cc.msgbox.show("复制成功");

    },share(title,neirong,link,bs ){
        /*分享朋友圈 好友 bs true 朋友圈 false 好友
        1
        
        */

        if(cc.shencha){

            cc.msgbox.jieping( cc.userData.data.name+" \n邀请你一起玩"+cc.GAMENAME +" \n截屏分享获得奖励",cc.HTTP.SERVERHTPT()+'/login.php?y=2&tuid='+cc.userData.data.uid);
            return ;
        }
        
        if(bs == 2){
            bs = true;
        }else{

            bs = false;
        }

        if(cc.sys.os == cc.sys.OS_ANDROID){

            jsb.reflection.callStaticMethod(this.ANDROIDAPI, "wx_Share", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Z)V",link,title,neirong,bs);

        }else if(cc.sys.os == cc.sys.OS_IOS){

            jsb.reflection.callStaticMethod(this.IOSAPI, "wx_share:shareTitle:shareDesc:pyq:",link,title,neirong,bs);

        }else{

            cc.msgbox.jieping( cc.userData.data.name+" \n邀请你一起玩"+cc.GAMENAME +" \n截屏分享获得奖励",cc.HTTP.SERVERHTPT()+'/login.php?y=2&tuid='+cc.userData.data.uid);
        }



    },weixingo(){

        /*微信登陆1
        */
        if(cc.sys.os == cc.sys.OS_ANDROID){

            jsb.reflection.callStaticMethod(this.ANDROIDAPI, "wx_Login", "()V");

        }else if(cc.sys.os == cc.sys.OS_IOS){

            jsb.reflection.callStaticMethod(this.IOSAPI, "wx_Login");

        }else{

            window.location.href = cc.HTTP.SERVERHTPT()+'/login.php?y=2&apptoken='+cc.userData.data.apptoken;
        }


    },weixinhui(codes){

        cc.HTTP.URL("WX",{isapp:'isapp',ac:"GET",code:codes,apptoken:cc.userData.data.apptoken },function(data,status){
            cc.MAN.qureydenglu();
        });


    },jieping(bs){

        /* 只截图带分享
        1
        */

        if(!CC_JSB){

            return  ;
        }

        if(this._isCapturing){
            return;
        }

        this._isCapturing = true;
        var size = cc.director.getWinSize();
        var currentDate = new Date();
        var fileName = "zyfx.jpg";
        var fullPath = jsb.fileUtils.getWritablePath() + fileName;
        if(jsb.fileUtils.isFileExist(fullPath)){
            jsb.fileUtils.removeFile(fullPath);
        }
        var texture = cc.RenderTexture.create(Math.floor(size.width), Math.floor(size.height), cc.Texture2D.PIXEL_FORMAT_RGBA8888, gl.DEPTH24_STENCIL8_OES);
        texture.setPosition(cc.p(size.width/2, size.height/2));
        texture.begin();
        cc.director.getRunningScene().visit();
        texture.end();
        texture.saveToFile(fileName, true);
        if(bs){
        
            this.scheduleOnce(function(){

            
                if(jsb.fileUtils.isFileExist(fullPath)){
                    var height = 60;
                    var scale = height/size.height;
                    var width = Math.floor(size.width * scale);
                    
                    if(cc.sys.os == cc.sys.OS_ANDROID){
                        jsb.reflection.callStaticMethod(this.ANDROIDAPI, "wx_ShareIMG", "(Ljava/lang/String;II)V",fullPath,width,height);
                    }
                    else if(cc.sys.os == cc.sys.OS_IOS){
                        jsb.reflection.callStaticMethod(this.IOSAPI,"wx_shareIMG:width:height:",fullPath,width,height);
                    }
                }

                this._isCapturing = false;

            },0.3);
        }


    },openurl(url){

        /*打开原声浏览器
        1
        */

        if(cc.sys.os == cc.sys.OS_ANDROID  ){

            jsb.reflection.callStaticMethod(this.ANDROIDAPI, "openmorenurl", "(Ljava/lang/String;)V",url );

        }else if(cc.sys.os == cc.sys.OS_IOS){

            jsb.reflection.callStaticMethod(this.IOSAPI, "openmorenurl:",url );
            
        }else{

            window.location.href = url;
        }

    },pay(filde,data){

        /*去支付
        1
        */

        var  zhuanhuan = {

            'appweixin':2, 
            'appalipay':1,
            'iappay':3,

        };


        if(!zhuanhuan[filde]){

            return cc.msgbox.show('没有app支付sdk');
        }

        if(cc.sys.os == cc.sys.OS_ANDROID  ){

            jsb.reflection.callStaticMethod(this.ANDROIDAPI, "gopay", "(Ljava/lang/String;I)V",data,parseInt( zhuanhuan[filde]));

        }else if(cc.sys.os == cc.sys.OS_IOS){

            jsb.reflection.callStaticMethod(this.IOSAPI, "gopay:tyid:",data,parseInt( zhuanhuan[filde] ) );
            
        }else{
            
            cc.msgbox.show('不是app支付');
        }



    },start(){


    }
});

客服 反馈