ionic2微信支付,分享,登录

ionic2微信支付,分享,登录

六月 09, 2017

安装
安装插件
cordova plugin add cordova-plugin-wechat –variable wechatappid=YOUR_WECHAT_APPID
安装ionic2、3调用
npm install wechat-chenyu –save
You also need to install the Ionic Native package for each plugin you want to add. Please see the Ionic Native documentation for complete instructions on how to add and use the plugins.

Documentation
For the full Ionic Native documentation, please visit https://ionicframework.com/docs/native/.

调用
To use a plugin, import and add the plugin provider to your @NgModule, and then inject it where you wish to use it.

// app.module.ts
import {WechatChenyu} from “wechat-chenyu”;

@NgModule({

providers: [

WechatChenyu

]

})
export class AppModule { }
import {WechatChenyu} from “wechat-chenyu”;

@Component({ … })
export class xxxxPage {
constructor(private wechatChenyu: WechatChenyu){}
//微信支付
// obj 是从服务器获取的参数
WchatPay(obj) {
console.log(obj);
let params = {
partnerid: obj.partnerid, // merchant id
prepayid: obj.prepayid, // prepay id
noncestr: obj.noncestr, // nonce
timestamp: obj.timestamp, // timestamp
sign: obj.sign
}
this.wechatChenyu.sendPaymentRequest(params).then((data) => {

    /*let alert = this.alertCtrl.create({
      title: '充值提示!',
      subTitle: JSON.stringify(data),
      buttons: ['确定']
    });
    alert.present();
    */
    }, eoor => {

    }
  );
}
//判断是否安装微信
isInstalled(){
  this.wechatChenyu.isInstalled().then();
}
//微信登录
auth(){
   this.wechatChenyu.auth().then(); 
}
//分享obj参考 https://www.npmjs.com/package/cordova-plugin-wechat
share(){
    let obj={
                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: 1   // 代表朋友圈、参数列表
            };
   this.wechatChenyu.share(obj).then();  
}

}
参数列表

scene 0, // 聊天界面 1, // 朋友圈 2 // 收藏

作者:杰骜不驯丶
版权声明:本文为博主原创文章,转载请附上博文链接!