首先去 https://open.weixin.qq.com/ 添加一個應用獲得appid 用來使用插件cordova-plugin-wechat
cordova plugin add cordova-plugin-wechat --variable wechatappid=wx****************
開通相關權限如登錄,分享,支付等。
填寫應用包名 注:對應config.xml 裏面 widget id="com.***.***" ;給apk簽名
providers目錄下建立wechat-plugin.ts (目錄隨便你能調用到就好)
declare var Wechat: any; // 此處聲明plugin.xml中clobbers對應的值
export interface WechatPayParam {
mch_id: string;
prepay_id: string;
nonce: string;
timestamp: string;
sign: string;
}
export class WechatPlugin {
public static isInstalled() {
return new Promise((resolve, reject) => {
Wechat.isInstalled(result => {
resolve(result);
}, error => {
reject(error);
});
});
}
public static sendPaymentRequest(params: WechatPayParam) {
return new Promise((resolve, reject) => {
Wechat.sendPaymentRequest(params, result => {
resolve(result);
}, error => {
reject(error);
});
});
}
public static auth() {
return new Promise((resolve, reject) => {
Wechat.auth(result => {
resolve(result);
}, error => {
reject(error);
});
});
}
}
由於是靜態方法 引入後直接點擊調用
import {WechatPlugin} from '../../providers/wechat-plugin';
注:本內容更具他人內容改版而來,若有冒犯請聯繫刪除 245429476@qq.com