@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 ADDED
@@ -0,0 +1,204 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+
191
+ Copyright (c) 2025 Huawei Device, Inc. Ltd. and <马弓手>.
192
+
193
+ Licensed under the Apache License, Version 2.0 (the "License");
194
+ you may not use this file except in compliance with the License.
195
+ You may obtain a copy of the License at
196
+
197
+ http://www.apache.org/licenses/LICENSE-2.0
198
+
199
+ Unless required by applicable law or agreed to in writing, software
200
+ distributed under the License is distributed on an "AS IS" BASIS,
201
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
202
+ See the License for the specific language governing permissions and
203
+ limitations under the License.
204
+
package/OAT.xml ADDED
@@ -0,0 +1,79 @@
1
+ <?xml version="1.0" encoding="UTF-8"?>
2
+ <!-- Copyright (c) 2021 Huawei Device Co., Ltd.
3
+
4
+ Licensed under the Apache License, Version 2.0 (the "License");
5
+ you may not use this file except in compliance with the License.
6
+ You may obtain a copy of the License at
7
+
8
+ http://www.apache.org/licenses/LICENSE-2.0
9
+
10
+ Unless required by applicable law or agreed to in writing, software
11
+ distributed under the License is distributed on an "AS IS" BASIS,
12
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
+ See the License for the specific language governing permissions and
14
+ limitations under the License.
15
+
16
+ This is the configuration file template for OpenHarmony OSS Audit Tool, please copy it to your project root dir and modify it refer to OpenHarmony/tools_oat/README.
17
+
18
+ -->
19
+
20
+ <configuration>
21
+ <oatconfig>
22
+ <licensefile></licensefile>
23
+ <policylist>
24
+ <policy name="projectPolicy" desc="">
25
+ <!--policyitem type="compatibility" name="GPL-2.0+" path="abc/.*" desc="Process that runs independently, invoked by the X process."/-->
26
+ <!--policyitem type="license" name="LGPL" path="abc/.*" desc="Dynamically linked by module X"/-->
27
+ <policyitem type="copyright" name="Copyright (c) 2025 Huawei Device, Inc. Ltd. and &lt;马弓手&gt;." path=".*" rule="may" group="defaultGroup" filefilter="copyrightPolicyFilter" desc="Developed by Huawei Device,Inc. Ltd. and &lt;马弓手&gt;"/>
28
+ </policy>
29
+ </policylist>
30
+ <filefilterlist>
31
+ <filefilter name="defaultFilter" desc="Files not to check">
32
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
33
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
34
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
35
+ </filefilter>
36
+ <filefilter name="defaultPolicyFilter" desc="Filters for compatibility,license header policies">
37
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
38
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
39
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
40
+ </filefilter>
41
+ <filefilter name="copyrightPolicyFilter" desc="Filters for copyright header policies">
42
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
43
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
44
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
45
+ </filefilter>
46
+ <filefilter name="licenseFileNamePolicyFilter" desc="Filters for LICENSE file policies">
47
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
48
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
49
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
50
+ </filefilter>
51
+ <filefilter name="readmeFileNamePolicyFilter" desc="Filters for README file policies">
52
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
53
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
54
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
55
+ </filefilter>
56
+ <filefilter name="readmeOpenSourcefileNamePolicyFilter" desc="Filters for README.OpenSource file policies">
57
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
58
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
59
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
60
+ </filefilter>
61
+ <filefilter name="binaryFileTypePolicyFilter" desc="Filters for binary file policies">
62
+ <!--filteritem type="filename" name="*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
63
+ <!--filteritem type="filepath" name="abcdefg/.*.uvwxyz" desc="Describe the reason for filtering scan results"/-->
64
+ <!--filteritem type="filepath" name="projectroot/[a-zA-Z0-9]{20,}.sh" desc="Temp files"/-->
65
+ </filefilter>
66
+
67
+ </filefilterlist>
68
+ <licensematcherlist>
69
+ <!--licensematcher name="uvwxyz License" desc="If the scanning result is InvalidLicense, you can define matching rules here. Note that quotation marks must be escaped.">
70
+ <licensetext name="
71
+ uvwxyz license textA xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
72
+ " desc=""/>
73
+ <licensetext name="
74
+ uvwxyz license textB xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
75
+ " desc=""/>
76
+ </licensematcher-->
77
+ </licensematcherlist>
78
+ </oatconfig>
79
+ </configuration>
package/README.md ADDED
@@ -0,0 +1,339 @@
1
+ # cordova-plugin-wechat
2
+
3
+ Cordova/PhoneGap 插件,用于在混合应用(Hybrid App)中集成微信 SDK,支持微信登录、分享、支付等核心功能,适配OHOS平台。
4
+
5
+ ## 功能特性
6
+
7
+ ✅ 检查微信客户端安装状态
8
+
9
+ ✅ 微信授权登录
10
+
11
+ ✅ 多类型分享(文本、图片、链接、小程序)
12
+
13
+ ✅ 微信支付(基于微信商户平台)
14
+
15
+ ✅ 打开微信客户端 / 指定页面
16
+
17
+ ✅ 完整的错误回调与状态提示
18
+
19
+ ## OHOS平台不支持以下功能
20
+ (1),微信Harmony SDK仅支持分享到聊天界面,不支持分享到朋友圈、收藏,scene字段无效;
21
+
22
+ (2),微信Harmony SDK不支持分享APP
23
+
24
+ (3),微信Harmony SDK不支持分享表情,表情可作为图片分享
25
+
26
+ (4),微信Harmony SDK不支持分享视频、音乐
27
+
28
+ ## 支持平台
29
+
30
+ * OHOS 5.0+
31
+
32
+
33
+ ## 前置准备
34
+
35
+
36
+
37
+ 1. 注册 [微信开放](https://open.weixin.qq.com/)[平台](https://open.weixin.qq.com/) 账号,创建移动应用
38
+
39
+ 2. 完善应用信息:
40
+
41
+ * OHOS:填写应用包名,上传签名文件等信息
42
+
43
+ 1. 申请所需接口权限(登录、分享、支付等),等待审核通过
44
+
45
+ 2. 若需支付功能:注册 [微信商户平](https://pay.weixin.qq.com/)[台](https://pay.weixin.qq.com/) 账号,绑定开放平台 AppID
46
+
47
+ ## 安装
48
+
49
+ 通过 HCordova CLI 安装(支持 cordova-openharmony 2.0.0+):
50
+
51
+ hcordova命令化工具 仓库:[OpenHarmony-Cordova/hcordova-cli](https://gitcode.com/OpenHarmony-Cordova/hcordova-cli)
52
+
53
+ ### 通过 npm 安装(推荐)
54
+
55
+
56
+
57
+ ```bash
58
+ hcordova plugin add cordova-plugin-wechat --variable WECHATAPPID=YOUR_WECHAT_APPID --platform ohos
59
+ ```
60
+
61
+
62
+ ## 卸载
63
+
64
+
65
+
66
+ ```bash
67
+ hcordova plugin remove cordova-plugin-wechat --variable WECHATAPPID=YOUR_WECHAT_APPID --platform ohos
68
+ ```
69
+
70
+ ## 配置说明
71
+
72
+ ### OHOS 额外配置
73
+
74
+
75
+
76
+ 1. 在开发者的 App module 的 module.json5 里加入下方scheme声明:
77
+
78
+
79
+
80
+ ```json
81
+ "querySchemes": [
82
+ "weixin",
83
+ "wxopensdk"
84
+ ]
85
+ ```
86
+
87
+
88
+ 2. 开发者需要先配置和微信约定的action wxentity.action.open:
89
+
90
+
91
+ ```json
92
+ "skills": [
93
+ {
94
+ "entities": [
95
+ "entity.system.home"
96
+ ],
97
+ "actions": [
98
+ "action.system.home",
99
+ "ohos.want.action.home",
100
+ "wxentity.action.open"
101
+ ]
102
+ }
103
+ ]
104
+ ```
105
+
106
+ 3. 修改项目中的oh-package.json5文件,在dependencies中加入微信 opensdk 的依赖项:
107
+
108
+
109
+ ```json
110
+ {
111
+ "name": "entry",
112
+ "version": "1.0.0",
113
+ "description": "Please describe the basic information.",
114
+ "main": "",
115
+ "author": "",
116
+ "license": "",
117
+ "dependencies": {
118
+ "@tencent/wechat_open_sdk": "^1.0.0",
119
+ "@magongshou/harmony-cordova": "file:../cordova"
120
+ }
121
+ }
122
+ ```
123
+
124
+ 4. 修改项目中的EntryAbility的代码,添加微信插件在ArkTS侧监听和初始化:
125
+
126
+
127
+ ```js
128
+ export default class EntryAbility extends UIAbility {
129
+ onCreate(want: Want, launchParam: AbilityConstant.LaunchParam): void {
130
+ //添加如下代码,注册Wechat监听插件
131
+ //WeChatAction/WeChatAction,动态导入微信插件
132
+ //EntryAbility 微信插件的入口函数
133
+ //wx9dab96bdfa8f16ec为app的appId,在微信的开放平台获取
134
+ PluginRegisterHandle(this,
135
+ want,
136
+ "WeChatAction/WeChatAction",
137
+ "EntryAbility",
138
+ "wx9dab96bdfa8f16ec"
139
+ );
140
+ }
141
+
142
+ onNewWant(want: Want): void {
143
+ //添加如下代码,注册Wechat监听插件
144
+ //WeChatAction/WeChatAction,动态导入微信插件
145
+ //EntryAbility 微信插件的入口函数
146
+ //wx9dab96bdfa8f16ec为app的appId,在微信的开放平台获取
147
+ PluginRegisterHandle(this,
148
+ want,
149
+ "WeChatAction/WeChatAction",
150
+ "EntryAbility",
151
+ "wx9dab96bdfa8f16ec"
152
+ );
153
+ }
154
+ }
155
+ ```
156
+
157
+
158
+ ## 使用示例
159
+
160
+ ### 1. 检查微信是否安装
161
+
162
+
163
+ ```js
164
+ //判断微信是否已经安装
165
+ Wechat.isInstalled(function (installed) {
166
+ alert("Wechat installed: " + (installed ? "Yes" : "No"));
167
+ }, function (reason) {
168
+ alert("Failed: " + reason);
169
+ });
170
+ ```
171
+
172
+ ### 2. 微信登录
173
+
174
+
175
+
176
+ ```js
177
+ //微信授权登录
178
+ var scope = "snsapi_userinfo",
179
+ state = "_" + (+new Date());
180
+ Wechat.auth(scope, state, function (response) {
181
+ alert("授权成功:根据服务端回调获取数据");
182
+ }, function (reason) {
183
+ alert("发送失败");
184
+ });
185
+ ```
186
+
187
+ ### 3. 分享文本到聊天界面
188
+
189
+
190
+ ```js
191
+ //分享文本到聊天界面
192
+ /*分享到微信后,无论是否分享成功,
193
+ *如果没有返回应用,js会回调分享成功,但不一定成功,
194
+ *如果返回了应用,分享失败,会通知js侧,分享成功不再通知
195
+ *这些都是SDK限制,插件无法更改
196
+ */
197
+ Wechat.share({
198
+ text: "This is just a plain string",
199
+ //scene属性无效
200
+ scene: Wechat.Scene.TIMELINE
201
+ }, function (response) {
202
+ //此处并不能判断是否真的分享成功,如果没有调失败就是成功的
203
+ console.log("Success");
204
+ }, function (reason) {
205
+ //如果返回了失败,是真的分享失败,会先调用成功
206
+ alert("Failed: " + reason);
207
+ });
208
+ ```
209
+
210
+ ### 4. 分享在线图片到聊天界面
211
+
212
+
213
+ ```js
214
+ //分享在线图片到聊天界面
215
+ /*通知js侧调用微信成功,分享是否成功无法判断,
216
+ *即使返回了应用也不通知js侧,
217
+ *这些都是SDK限制,插件无法更改
218
+ */
219
+ Wechat.share({
220
+ message: {
221
+ media: {
222
+ type:Wechat.Type.IMAGE,
223
+ image:"https://www.chuzhitong.com/images/logo.png"
224
+ }
225
+ },
226
+ //scene属性无效
227
+ scene: Wechat.Scene.TIMELINE
228
+ }, function (response) {
229
+ console.log("Success");
230
+ }, function (reason) {
231
+ console.log("Failed: " + reason);
232
+ });
233
+ ```
234
+
235
+ ### 5. 分享base64图片到聊天界面
236
+
237
+
238
+ ```js
239
+ //分享base64图片到聊天界面
240
+ /*通知js侧调用微信成功,分享是否成功无法判断,
241
+ *即使返回了应用也不通知js侧,
242
+ *这些都是SDK限制,插件无法更改
243
+ */
244
+ Wechat.share({
245
+ message: {
246
+ media: {
247
+ type:Wechat.Type.IMAGE,
248
+ image:"data:image/jpeg;base64,djfksjfdlsf...."
249
+ }
250
+ },
251
+ //scene属性无效
252
+ scene: Wechat.Scene.TIMELINE
253
+ }, function (response) {
254
+ console.log("Success");
255
+ }, function (reason) {
256
+ console.log("Failed: " + reason);
257
+ });
258
+ ```
259
+
260
+ ### 6. 分享小程序
261
+
262
+
263
+ ```js
264
+ //分享小程序
265
+ /*分享到微信后,无论是否分享成功,
266
+ *如果没有返回应用,js会回调分享成功,但不一定成功,
267
+ *如果返回了应用,分享失败,会通知js侧,分享成功不再通知
268
+ *这些都是SDK限制,插件无法更改
269
+ */
270
+ Wechat.share({
271
+ message: {
272
+ title: "Hi, there",
273
+ description: "This is description.",
274
+ thumb: "https://www.chuzhitong.com/images/logo.png",
275
+ media: {
276
+ type: Wechat.Type.MINI,
277
+ userName: "gh_946331c270fa", // 小程序原始id
278
+ path: "pages/contact/contact", // 小程序的页面路径
279
+ withShareTicket: true, // 是否使用带shareTicket的分享
280
+ miniprogramType: Wechat.Mini.RELEASE
281
+ }
282
+ },
283
+ scene: Wechat.Scene.SESSION // 小程序仅支持聊天界面
284
+ }, function (response) {
285
+ console.log(response);
286
+ }, function (reason) {
287
+ console.log(reason);
288
+ });
289
+ ```
290
+
291
+ ### 7. 打开小程序
292
+
293
+
294
+ ```js
295
+ //打开小程序
296
+ var params = {
297
+ userName: 'gh_946331c270fa', // userName
298
+ path: 'pages/contact/contact', // open mini program page
299
+ // Developer, trial, and official version
300
+ miniprogramType: Wechat.Mini.RELEASE
301
+ };
302
+ Wechat.openMiniProgram(params,function(response){
303
+ alert(response);
304
+ },function(reason){
305
+ alert(reason);
306
+ })
307
+ ```
308
+
309
+ ### 8. 调起微信支付
310
+
311
+
312
+ ```js
313
+ //调起微信支付,数据由web服务端生成返回给APP前端,然后前端调起支付界面
314
+ var params = {
315
+ partnerid: '1573080401', // merchant id
316
+ prepayid: 'wx08130020798076c61ca4d6b876b7490000', // prepay id
317
+ noncestr: 'a8a7db499852484dac2a6fa350980a16', // nonce
318
+ timestamp: '1762578047', // timestamp
319
+ sign: 'ChzOmrXDyKJa6AFAZZ....', // signed string
320
+ };
321
+
322
+ Wechat.sendPaymentRequest(params, function () {
323
+ alert("Success");
324
+ }, function (reason) {
325
+ alert("Failed: " + reason);
326
+ });
327
+ ```
328
+ ## 许可证
329
+
330
+ 本插件基于 [Apache License 2.0](LICENSE) 开源,详情见 LICENSE 文件。
331
+
332
+ ## 官方资源
333
+
334
+
335
+ * Android和iOS:[cordova-plugin-wechat 官方指南](https://www.npmjs.com/package/cordova-plugin-wechat)
336
+
337
+ * GitCode 仓库:[OpenHarmony-Cordova/cordova-plugin-wechat](https://gitcode.com/OpenHarmony-Cordova/cordova-plugin-wechat)
338
+
339
+ * 问题反馈:[提交 Issue](https://gitcode.com/OpenHarmony-Cordova/cordova-plugin-wechat/issues)
package/package.json ADDED
@@ -0,0 +1,29 @@
1
+ {
2
+ "name": "@cordova-ohos/cordova-plugin-wechat",
3
+ "version": "3.1.0",
4
+ "description": "Cordova Wechat Plugin",
5
+ "cordova": {
6
+ "id": "cordova-plugin-wechat",
7
+ "platforms": [
8
+ "ohos"
9
+ ]
10
+ },
11
+ "repository": "gitcode:OpenHarmony-Cordova/cordova-plugin-wechat",
12
+ "bugs": "https://gitcode.com/OpenHarmony-Cordova/cordova-plugin-wechat/issues",
13
+ "keywords": [
14
+ "cordova",
15
+ "wechat",
16
+ "ecosystem:cordova",
17
+ "cordova-openharmony"
18
+ ],
19
+ "engines": {
20
+ "cordovaDependencies": {
21
+ "3.1.0": {
22
+ "@cordova-ohos/ohos": ">=2.0.0",
23
+ "hcordova":">=1.0.0"
24
+ }
25
+ }
26
+ },
27
+ "author": " Huawei Device, Inc. Ltd. and <马弓手>",
28
+ "license": "Apache-2.0"
29
+ }