@cordova-ohos/cordova-plugin-wechat 3.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +204 -0
- package/OAT.xml +79 -0
- package/README.md +339 -0
- package/package.json +29 -0
- package/plugin.xml +54 -0
- package/src/main/cpp/Wechat/Wechat.cpp +607 -0
- package/src/main/cpp/Wechat/Wechat.h +42 -0
- package/src/main/ets/components/WeChatAction/WeChatAction.ets +621 -0
- package/www/wechat.js +195 -0
package/www/wechat.js
ADDED
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
var exec = require('cordova/exec');
|
|
2
|
+
|
|
3
|
+
module.exports = {
|
|
4
|
+
Scene: {
|
|
5
|
+
SESSION: 0, // 聊天界面
|
|
6
|
+
TIMELINE: 1, // 朋友圈
|
|
7
|
+
FAVORITE: 2 // 收藏
|
|
8
|
+
},
|
|
9
|
+
|
|
10
|
+
Type: {
|
|
11
|
+
APP: 1,
|
|
12
|
+
EMOTION: 2,
|
|
13
|
+
FILE: 3,
|
|
14
|
+
IMAGE: 4,
|
|
15
|
+
MUSIC: 5,
|
|
16
|
+
VIDEO: 6,
|
|
17
|
+
WEBPAGE: 7,
|
|
18
|
+
MINI: 8
|
|
19
|
+
},
|
|
20
|
+
|
|
21
|
+
Mini: {
|
|
22
|
+
RELEASE: 0, // 正式版
|
|
23
|
+
TEST: 1, // 测试版
|
|
24
|
+
PREVIEW: 2 // 体验版
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
Events: {
|
|
28
|
+
// 通过微信打开,回调传入 extinfo 参数
|
|
29
|
+
LaunchFromWX: 'wechat.launchFromWX'
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
isInstalled: function (onSuccess, onError) {
|
|
33
|
+
exec(onSuccess, onError, "Wechat", "isWXAppInstalled", []);
|
|
34
|
+
},
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Share a message to wechat app
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* <code>
|
|
41
|
+
* Wechat.share({
|
|
42
|
+
* message: {
|
|
43
|
+
* title: "Message Title",
|
|
44
|
+
* description: "Message Description(optional)",
|
|
45
|
+
* mediaTagName: "Media Tag Name(optional)",
|
|
46
|
+
* thumb: "http://YOUR_THUMBNAIL_IMAGE",
|
|
47
|
+
* media: {
|
|
48
|
+
* type: Wechat.Type.WEBPAGE, // webpage
|
|
49
|
+
* webpageUrl: "https://github.com/xu-li/cordova-plugin-wechat" // webpage
|
|
50
|
+
* }
|
|
51
|
+
* },
|
|
52
|
+
* scene: Wechat.Scene.TIMELINE // share to Timeline
|
|
53
|
+
* }, function () {
|
|
54
|
+
* alert("Success");
|
|
55
|
+
* }, function (reason) {
|
|
56
|
+
* alert("Failed: " + reason);
|
|
57
|
+
* });
|
|
58
|
+
* </code>
|
|
59
|
+
*/
|
|
60
|
+
share: function (message, onSuccess, onError) {
|
|
61
|
+
exec(onSuccess, onError, "Wechat", "share", [message]);
|
|
62
|
+
},
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Sending an auth request to Wechat
|
|
66
|
+
*
|
|
67
|
+
* @example
|
|
68
|
+
* <code>
|
|
69
|
+
* Wechat.auth(function (response) { alert(response.code); });
|
|
70
|
+
* </code>
|
|
71
|
+
*/
|
|
72
|
+
auth: function (scope, state, onSuccess, onError) {
|
|
73
|
+
if (typeof scope == "function") {
|
|
74
|
+
// Wechat.auth(function () { alert("Success"); });
|
|
75
|
+
// Wechat.auth(function () { alert("Success"); }, function (error) { alert(error); });
|
|
76
|
+
return exec(scope, state, "Wechat", "sendAuthRequest");
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
if (typeof state == "function") {
|
|
80
|
+
// Wechat.auth("snsapi_userinfo", function () { alert("Success"); });
|
|
81
|
+
// Wechat.auth("snsapi_userinfo", function () { alert("Success"); }, function (error) { alert(error); });
|
|
82
|
+
return exec(state, onSuccess, "Wechat", "sendAuthRequest", [scope]);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
return exec(onSuccess, onError, "Wechat", "sendAuthRequest", [scope, state]);
|
|
86
|
+
},
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Send a payment request
|
|
90
|
+
*
|
|
91
|
+
* @link https://pay.weixin.qq.com/wiki/doc/api/app.php?chapter=9_1
|
|
92
|
+
* @example
|
|
93
|
+
* <code>
|
|
94
|
+
* var params = {
|
|
95
|
+
* mch_id: '10000100', // merchant id
|
|
96
|
+
* prepay_id: 'wx201411101639507cbf6ffd8b0779950874', // prepay id returned from server
|
|
97
|
+
* nonce: '1add1a30ac87aa2db72f57a2375d8fec', // nonce string returned from server
|
|
98
|
+
* timestamp: '1439531364', // timestamp
|
|
99
|
+
* sign: '0CB01533B8C1EF103065174F50BCA001', // signed string
|
|
100
|
+
* };
|
|
101
|
+
* Wechat.sendPaymentRequest(params, function () {
|
|
102
|
+
* alert("Success");
|
|
103
|
+
* }, function (reason) {
|
|
104
|
+
* alert("Failed: " + reason);
|
|
105
|
+
* });
|
|
106
|
+
* </code>
|
|
107
|
+
*/
|
|
108
|
+
sendPaymentRequest: function (params, onSuccess, onError) {
|
|
109
|
+
exec(onSuccess, onError, "Wechat", "sendPaymentRequest", [params]);
|
|
110
|
+
},
|
|
111
|
+
|
|
112
|
+
/**
|
|
113
|
+
* jumpToBizProfile (跳转到某个微信公众号)2016-11-11 测试是失效的,囧
|
|
114
|
+
*
|
|
115
|
+
* @link https://segmentfault.com/a/1190000007204624
|
|
116
|
+
* @link https://segmentfault.com/q/1010000003907796
|
|
117
|
+
* @example
|
|
118
|
+
* <code>
|
|
119
|
+
* var params = {
|
|
120
|
+
* info: 'gh_xxxxxxx', // 公众帐号原始ID
|
|
121
|
+
* type: 'Normal' // 普通号
|
|
122
|
+
* }
|
|
123
|
+
* or
|
|
124
|
+
* var params = {
|
|
125
|
+
* info: 'extMsg', // 相关的硬件二维码串
|
|
126
|
+
* type: 'Device' // 硬件号
|
|
127
|
+
* };
|
|
128
|
+
* Wechat.jumpToBizProfile(params, function () {
|
|
129
|
+
* alert("Success");
|
|
130
|
+
* }, function (reason) {
|
|
131
|
+
* alert("Failed: " + reason);
|
|
132
|
+
* });
|
|
133
|
+
* </code>
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
jumpToBizProfile: function (params, onSuccess, onError) {
|
|
137
|
+
exec(onSuccess, onError, "Wechat", "jumpToBizProfile", [params]);
|
|
138
|
+
},
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* jumpToWechat (因为jumpToBizProfile失效了,暂时新增了一个临时的api)
|
|
142
|
+
*
|
|
143
|
+
* @link https://segmentfault.com/a/1190000007204624
|
|
144
|
+
* @example
|
|
145
|
+
* <code>
|
|
146
|
+
* var url = "wechat://" 现阶段貌似只支持这一个协议了
|
|
147
|
+
* Wechat.jumpToWechat(url, function () {
|
|
148
|
+
* alert("Success");
|
|
149
|
+
* }, function (reason) {
|
|
150
|
+
* alert("Failed: " + reason);
|
|
151
|
+
* });
|
|
152
|
+
* </code>
|
|
153
|
+
*/
|
|
154
|
+
jumpToWechat: function (url, onSuccess, onError) {
|
|
155
|
+
exec(onSuccess, onError, "Wechat", "jumpToWechat", [url]);
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
/**
|
|
159
|
+
* chooseInvoiceFromWX exq:choose invoices from Wechat card list
|
|
160
|
+
*
|
|
161
|
+
* @example
|
|
162
|
+
* <code>
|
|
163
|
+
* params: signType, cardSign, nonceStr, timeStamp all required
|
|
164
|
+
* Wechat.chooseInvoiceFromWX(params, function () {
|
|
165
|
+
* alert("Success");
|
|
166
|
+
* }, function (reason) {
|
|
167
|
+
* alert("Failed: " + reason);
|
|
168
|
+
* });
|
|
169
|
+
* </code>
|
|
170
|
+
*/
|
|
171
|
+
chooseInvoiceFromWX: function (params, onSuccess, onError) {
|
|
172
|
+
exec(onSuccess, onError, "Wechat", "chooseInvoiceFromWX", [params]);
|
|
173
|
+
},
|
|
174
|
+
|
|
175
|
+
/**
|
|
176
|
+
* openMiniProgram exq:app opens wechat mini program
|
|
177
|
+
*
|
|
178
|
+
* @example
|
|
179
|
+
* <code>
|
|
180
|
+
* params: userName, path, miniprogramType all required
|
|
181
|
+
* Wechat.openMiniProgram(params, function (data) {
|
|
182
|
+
* alert(data.extMsg);
|
|
183
|
+
* }, function (reason) {
|
|
184
|
+
* alert("Failed: " + reason);
|
|
185
|
+
* });
|
|
186
|
+
* </code>
|
|
187
|
+
*/
|
|
188
|
+
openMiniProgram: function (params, onSuccess, onError) {
|
|
189
|
+
exec(onSuccess, onError, "Wechat", "openMiniProgram", [params]);
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
minProgram: function (params, onSuccess, onError) {
|
|
193
|
+
exec(onSuccess, onError, "Wechat", "minProgram", [params]);
|
|
194
|
+
}
|
|
195
|
+
};
|