美文网首页Ionic
ionic 微信接口

ionic 微信接口

作者: 柳暗花明又一匪 | 来源:发表于2018-02-09 10:13 被阅读208次

    1:将config.xml里面的<widget id="app包的名字" version="0.0.1" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">里面的id改为你的app包的名字(如:org.cadm.app)

    获取openid
    http://blog.csdn.net/liayn523/article/details/78415440

    2:将ionic.config.json里面的name改为你的app的名字(如:cadm),app_id改为app包的名字(如:org.cadm.app)

    3,修改package_name**

    • 修改ionic.config.json中app_id(PACKAGE_NAME):你的app包的名字(com.dengdd.sdkdemo)
    • 修改/plugins/android.json中所有PACKAGE_NEME为这个值:你的app包的名字(com.dengdd.sdkdemo)

    4,安装插件

    cordova plugin add cordova-plugin-wechat --variable wechatappid=你申请微信appid
    cordova plugin add cordova-plugin-qqsdk --variable QQ_APP_ID=你申请QQ的appid
    cordova plugin add cordova-plugin-weibosdk --variable WEIBO_APP_ID=你申请微博的appid
    
    

    微信登录[https://www.npmjs.com/package/cordova-plugin-wechat]
    [https://github.com/xu-li/cordova-plugin-wechat]

    cordova plugin add cordova-plugin-wechat --variable wechatappid=YOUR_WECHAT_APPID
    cordova build ios or cordova build android
    

    YOUR_WECHAT_APPID 微信开放平台
    在需要用到的页面组件引入:

    declare let Wechat;
    
    image.png

    判断是否安装微信

    Wechat.isInstalled(function (installed) {
        alert("Wechat installed: " + (installed ? "Yes" : "No"));
    }, function (reason) {
        alert("Failed: " + reason);
    });
    

    请求微信登录

    var scope = "snsapi_userinfo",
        state = "_" + (+new Date());
    Wechat.auth(scope, state, function (response) {
        // you may use response.code to get the access token.
        alert(JSON.stringify(response));
    }, function (reason) {
        alert("Failed: " + reason);
    });
    

    分享文字

    Wechat.share({
        text: "This is just a plain string",
        scene: Wechat.Scene.TIMELINE   // share to Timeline
    }, function () {
        alert("Success");
    }, function (reason) {
        alert("Failed: " + reason);
    });
    

    分享媒体(如链接,照片,音乐,视频等)

    Wechat.share({
        message: {
            title: "Hi, there",
            description: "This is description.",
            thumb: "www/img/thumbnail.png",
            mediaTagName: "TEST-TAG-001",
            messageExt: "这是第三方带的测试字段",
            messageAction: "<action>dotalist</action>",
            media: "YOUR_MEDIA_OBJECT_HERE"
        },
        scene: Wechat.Scene.TIMELINE   // share to Timeline
    }, function () {
        alert("Success");
    }, function (reason) {
        alert("Failed: " + reason);
    });
    

    分享链接

    Wechat.share({
        message: {
            ...
            media: {
                type: Wechat.Type.WEBPAGE,
                webpageUrl: "http://tech.qq.com/zt2012/tmtdecode/252.htm"
            }
        },
        scene: Wechat.Scene.TIMELINE   // share to Timeline
    }, function () {
        alert("Success");
    }, function (reason) {
        alert("Failed: " + reason);
    });
    

    发起支付请求

    // See https://github.com/xu-li/cordova-plugin-wechat-example/blob/master/server/payment_demo.php for php demo
    var params = {
        partnerid: '10000100', // merchant id
        prepayid: 'wx201411101639507cbf6ffd8b0779950874', // prepay id
        noncestr: '1add1a30ac87aa2db72f57a2375d8fec', // nonce
        timestamp: '1439531364', // timestamp
        sign: '0CB01533B8C1EF103065174F50BCA001', // signed string
    };
     
    Wechat.sendPaymentRequest(params, function () {
        alert("Success");
    }, function (reason) {
        alert("Failed: " + reason);
    });
    

    选择发票

    //offical doc https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1496561749_f7T6D
    var params = {
        timeStamp: '1510198391', // timeStamp
        signType: 'SHA1', // sign type
        cardSign: 'dff450eeeed08120159d285e79737173aec3df94', // cardSign
        nonceStr: '5598190f-5fb3-4bff-8314-fd189ab4e4b8', // nonce
    };
     
    Wechat.chooseInvoiceFromWX(data,function(data){
        console.log(data);
    },function(){
        alert('error');
    })
    

    相关文章

      网友评论

      • _听风细雨:你好微信支付闪退什么原因啊
      • e4e074a62da6:您好,我在微信拉发票那个地方遇到一点问题,我的qq;595449323,能加我个qq号咨询一下吗?多谢了

      本文标题:ionic 微信接口

      本文链接:https://www.haomeiwen.com/subject/yralaxtx.html