@hairy/wechat-jssdk 1.2.10 → 1.6.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 → LICENSE.md} +1 -3
- package/README.md +66 -0
- package/dist/index.cjs +17 -22
- package/dist/index.d.ts +105 -105
- package/dist/index.global.js +253 -0
- package/dist/{index.mjs → index.js} +13 -8
- package/package.json +23 -11
package/{LICENSE → LICENSE.md}
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c)
|
|
3
|
+
Copyright (c) 2025-PRESENT Hairyf <https://github.com/antfu>
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
6
|
of this software and associated documentation files (the "Software"), to deal
|
|
@@ -19,5 +19,3 @@ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
19
19
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
20
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
21
|
SOFTWARE.
|
|
22
|
-
|
|
23
|
-
|
package/README.md
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# @hairy/wechat-jssdk
|
|
2
|
+
|
|
3
|
+
[![npm version][npm-version-src]][npm-version-href]
|
|
4
|
+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
|
|
5
|
+
[![bundle][bundle-src]][bundle-href]
|
|
6
|
+
[![JSDocs][jsdocs-src]][jsdocs-href]
|
|
7
|
+
[![License][license-src]][license-href]
|
|
8
|
+
|
|
9
|
+
WechatJssdk 构造函数对 [wechat-jssdk](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html) 的 `api` 进行了 `promise` 处理,并且可直接调用,不需要执行 `wx.ready` 等待 `jssdk` 授权完毕。
|
|
10
|
+
|
|
11
|
+
初始化不需要执行 `wx.config`,内部会根据传入的 `config request`,请求签名并自动调用 `wx.config`。
|
|
12
|
+
|
|
13
|
+
## Install
|
|
14
|
+
|
|
15
|
+
```
|
|
16
|
+
ni @hairy/wechat-jssdk
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
## CDN
|
|
20
|
+
|
|
21
|
+
```html
|
|
22
|
+
<script src="https://unpkg.com/@hairy/wechat-jssdk"></script>
|
|
23
|
+
```
|
|
24
|
+
|
|
25
|
+
## Usage
|
|
26
|
+
```ts
|
|
27
|
+
import { WechatJssdk } from '@hairy/wechat-jssdk'
|
|
28
|
+
|
|
29
|
+
export const wxJssdk = new WechatJssdk({
|
|
30
|
+
requestConfig: async () => {
|
|
31
|
+
return {
|
|
32
|
+
appId: '...',
|
|
33
|
+
jsApiList: ['onMenuShareAppMessage'],
|
|
34
|
+
nonceStr: '...',
|
|
35
|
+
signature: '...',
|
|
36
|
+
timestamp: 13_123
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
await wxJssdk.updateAppMessageShareData({
|
|
42
|
+
title: '...',
|
|
43
|
+
desc: '...',
|
|
44
|
+
link: '...',
|
|
45
|
+
imgUrl: '...'
|
|
46
|
+
})
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
> api 与 [wechat-jssdk](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html) 保持一致。
|
|
50
|
+
|
|
51
|
+
## License
|
|
52
|
+
|
|
53
|
+
[MIT](./LICENSE) License © [Hairyf](https://github.com/hairyf)
|
|
54
|
+
|
|
55
|
+
<!-- Badges -->
|
|
56
|
+
|
|
57
|
+
[npm-version-src]: https://img.shields.io/npm/v/@hairy/wechat-jssdk?style=flat&colorA=080f12&colorB=1fa669
|
|
58
|
+
[npm-version-href]: https://npmjs.com/package/@hairy/wechat-jssdk
|
|
59
|
+
[npm-downloads-src]: https://img.shields.io/npm/dm/@hairy/wechat-jssdk?style=flat&colorA=080f12&colorB=1fa669
|
|
60
|
+
[npm-downloads-href]: https://npmjs.com/package/@hairy/wechat-jssdk
|
|
61
|
+
[bundle-src]: https://img.shields.io/bundlephobia/minzip/@hairy/wechat-jssdk?style=flat&colorA=080f12&colorB=1fa669&label=minzip
|
|
62
|
+
[bundle-href]: https://bundlephobia.com/result?p=@hairy/wechat-jssdk
|
|
63
|
+
[license-src]: https://img.shields.io/github/license/hairyf/hairylib.svg?style=flat&colorA=080f12&colorB=1fa669
|
|
64
|
+
[license-href]: https://github.com/hairyf/hairylib/blob/main/LICENSE
|
|
65
|
+
[jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
|
|
66
|
+
[jsdocs-href]: https://www.jsdocs.io/package/@hairy/wechat-jssdk
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __create = Object.create;
|
|
3
2
|
var __defProp = Object.defineProperty;
|
|
4
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
5
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
6
|
var __export = (target, all) => {
|
|
9
7
|
for (var name in all)
|
|
@@ -17,26 +15,18 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
15
|
}
|
|
18
16
|
return to;
|
|
19
17
|
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
19
|
|
|
30
20
|
// src/index.ts
|
|
31
|
-
var
|
|
32
|
-
__export(
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
33
23
|
WechatJssdk: () => WechatJssdk
|
|
34
24
|
});
|
|
35
|
-
module.exports = __toCommonJS(
|
|
25
|
+
module.exports = __toCommonJS(index_exports);
|
|
36
26
|
|
|
37
27
|
// src/internal/load_script.ts
|
|
38
|
-
var
|
|
39
|
-
function loadScript(source, onLoaded =
|
|
28
|
+
var import_utils = require("@hairy/utils");
|
|
29
|
+
function loadScript(source, onLoaded = import_utils.noop, options = {}) {
|
|
40
30
|
const {
|
|
41
31
|
type = "text/javascript",
|
|
42
32
|
async = true,
|
|
@@ -82,8 +72,19 @@ function loadScript(source, onLoaded = import_noop.default, options = {}) {
|
|
|
82
72
|
|
|
83
73
|
// src/helper.ts
|
|
84
74
|
var WechatJssdkHelper = class {
|
|
75
|
+
version;
|
|
76
|
+
isReady = false;
|
|
77
|
+
requestConfig;
|
|
78
|
+
loadPromise;
|
|
79
|
+
configPromise;
|
|
80
|
+
readyPromise;
|
|
81
|
+
loadJssdk() {
|
|
82
|
+
const scriptUrl = `https://res.wx.qq.com/open/js/jweixin-${this.version}.js`;
|
|
83
|
+
this.loadPromise = loadScript(scriptUrl).then(() => {
|
|
84
|
+
this.loadPromise = void 0;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
85
87
|
constructor(options) {
|
|
86
|
-
this.isReady = false;
|
|
87
88
|
const { immediate = true, version, requestConfig } = options;
|
|
88
89
|
this.version = version || "1.3.0";
|
|
89
90
|
this.requestConfig = requestConfig;
|
|
@@ -91,12 +92,6 @@ var WechatJssdkHelper = class {
|
|
|
91
92
|
if (immediate)
|
|
92
93
|
this.config();
|
|
93
94
|
}
|
|
94
|
-
loadJssdk() {
|
|
95
|
-
const scriptUrl = `https://res.wx.qq.com/open/js/jweixin-${this.version}.js`;
|
|
96
|
-
this.loadPromise = loadScript(scriptUrl).then(() => {
|
|
97
|
-
this.loadPromise = void 0;
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
95
|
async config() {
|
|
101
96
|
if (this.configPromise)
|
|
102
97
|
return this.configPromise;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,114 +1,114 @@
|
|
|
1
1
|
import * as WxType from 'jweixin';
|
|
2
2
|
|
|
3
|
-
declare module 'jweixin' {
|
|
4
|
-
type v4ApiMethod = 'updateTimelineShareData' | 'updateAppMessageShareData';
|
|
5
|
-
function config(config_: {
|
|
6
|
-
debug?: boolean | undefined;
|
|
7
|
-
appId: string;
|
|
8
|
-
timestamp: number;
|
|
9
|
-
nonceStr: string;
|
|
10
|
-
signature: string;
|
|
11
|
-
jsApiList: (WxType.ApiMethod | v4ApiMethod)[];
|
|
12
|
-
}): void;
|
|
13
|
-
}
|
|
14
|
-
declare global {
|
|
15
|
-
const wx: typeof WxType;
|
|
16
|
-
}
|
|
17
|
-
type WechatJssdkConfig = Omit<Parameters<typeof wx.config>[0], 'catch' | 'finally' | 'then'>;
|
|
18
|
-
interface WechatJssdkOptions {
|
|
19
|
-
/**
|
|
20
|
-
* 初始化请求配置
|
|
21
|
-
*/
|
|
22
|
-
requestConfig: () => Promise<WechatJssdkConfig> | WechatJssdkConfig;
|
|
23
|
-
/**
|
|
24
|
-
* 是否立即加载 config
|
|
25
|
-
*
|
|
26
|
-
* @default true
|
|
27
|
-
*/
|
|
28
|
-
immediate?: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* wechat-jssdk 版本
|
|
31
|
-
*
|
|
32
|
-
* @default 1.3.0
|
|
33
|
-
*/
|
|
34
|
-
version?: '1.2.0' | '1.3.0' | '1.4.0' | '1.5.0' | '1.6.0';
|
|
3
|
+
declare module 'jweixin' {
|
|
4
|
+
type v4ApiMethod = 'updateTimelineShareData' | 'updateAppMessageShareData';
|
|
5
|
+
function config(config_: {
|
|
6
|
+
debug?: boolean | undefined;
|
|
7
|
+
appId: string;
|
|
8
|
+
timestamp: number;
|
|
9
|
+
nonceStr: string;
|
|
10
|
+
signature: string;
|
|
11
|
+
jsApiList: (WxType.ApiMethod | v4ApiMethod)[];
|
|
12
|
+
}): void;
|
|
13
|
+
}
|
|
14
|
+
declare global {
|
|
15
|
+
const wx: typeof WxType;
|
|
16
|
+
}
|
|
17
|
+
type WechatJssdkConfig = Omit<Parameters<typeof wx.config>[0], 'catch' | 'finally' | 'then'>;
|
|
18
|
+
interface WechatJssdkOptions {
|
|
19
|
+
/**
|
|
20
|
+
* 初始化请求配置
|
|
21
|
+
*/
|
|
22
|
+
requestConfig: () => Promise<WechatJssdkConfig> | WechatJssdkConfig;
|
|
23
|
+
/**
|
|
24
|
+
* 是否立即加载 config
|
|
25
|
+
*
|
|
26
|
+
* @default true
|
|
27
|
+
*/
|
|
28
|
+
immediate?: boolean;
|
|
29
|
+
/**
|
|
30
|
+
* wechat-jssdk 版本
|
|
31
|
+
*
|
|
32
|
+
* @default 1.3.0
|
|
33
|
+
*/
|
|
34
|
+
version?: '1.2.0' | '1.3.0' | '1.4.0' | '1.5.0' | '1.6.0';
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
/**
|
|
38
|
-
* jssdk 的前置处理类
|
|
39
|
-
* @constructor 加载配置(apiHost,appId,config,version,jssdk)
|
|
40
|
-
* @function implement 提供 wxApi 执行器(等待 config 与 ready 结束,在调用 api)
|
|
41
|
-
* @function config 加载配置,提供 promise 式返回
|
|
42
|
-
* @function ready wx.
|
|
43
|
-
*/
|
|
44
|
-
declare class WechatJssdkHelper {
|
|
45
|
-
private version;
|
|
46
|
-
private isReady;
|
|
47
|
-
private requestConfig;
|
|
48
|
-
private loadPromise?;
|
|
49
|
-
private configPromise?;
|
|
50
|
-
private readyPromise?;
|
|
51
|
-
private loadJssdk;
|
|
52
|
-
constructor(options: WechatJssdkOptions);
|
|
53
|
-
config(): Promise<void>;
|
|
54
|
-
ready(): Promise<void>;
|
|
55
|
-
error(): Promise<any>;
|
|
56
|
-
protected implement<Key extends keyof typeof wx | string>(key: Key, options?: any): Promise<void>;
|
|
37
|
+
/**
|
|
38
|
+
* jssdk 的前置处理类
|
|
39
|
+
* @constructor 加载配置(apiHost,appId,config,version,jssdk)
|
|
40
|
+
* @function implement 提供 wxApi 执行器(等待 config 与 ready 结束,在调用 api)
|
|
41
|
+
* @function config 加载配置,提供 promise 式返回
|
|
42
|
+
* @function ready wx.ready,提供 promise 式返回
|
|
43
|
+
*/
|
|
44
|
+
declare class WechatJssdkHelper {
|
|
45
|
+
private version;
|
|
46
|
+
private isReady;
|
|
47
|
+
private requestConfig;
|
|
48
|
+
private loadPromise?;
|
|
49
|
+
private configPromise?;
|
|
50
|
+
private readyPromise?;
|
|
51
|
+
private loadJssdk;
|
|
52
|
+
constructor(options: WechatJssdkOptions);
|
|
53
|
+
config(): Promise<void>;
|
|
54
|
+
ready(): Promise<void>;
|
|
55
|
+
error(): Promise<any>;
|
|
56
|
+
protected implement<Key extends keyof typeof wx | string>(key: Key, options?: any): Promise<void>;
|
|
57
57
|
}
|
|
58
58
|
|
|
59
|
-
/**
|
|
60
|
-
* @description WechatJssdk Api 封装,与 [jssdk 文档](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html) 保持一致,主要以下改动
|
|
61
|
-
* @description 内置请求,读取 config 配置,初始化自动调用 wx.config
|
|
62
|
-
* @description 所有 api 的 promise 化处理(仅等待 wx.ready)
|
|
63
|
-
* @description 简易化初始化构建,config 处理
|
|
64
|
-
* @description 可指定加载 jssdk 版本(默认 1.3.0)
|
|
65
|
-
* @template `const wxJssdk = new WechatJssdk({env, config})`
|
|
66
|
-
*/
|
|
67
|
-
declare class WechatJssdk extends WechatJssdkHelper {
|
|
68
|
-
constructor(options: WechatJssdkOptions);
|
|
69
|
-
updateAppMessageShareData(options: WxType.IonMenuShareAppMessage): Promise<void>;
|
|
70
|
-
updateTimelineShareData(options: WxType.IonMenuShareAppMessage): Promise<void>;
|
|
71
|
-
addCard(): Promise<void>;
|
|
72
|
-
checkJsApi(options: WxType.IcheckJsApi): Promise<void>;
|
|
73
|
-
chooseCard(options: WxType.IchooseCard): Promise<void>;
|
|
74
|
-
chooseImage(options: WxType.IchooseImage): Promise<void>;
|
|
75
|
-
chooseWXPay(options: WxType.IchooseWXPay): Promise<void>;
|
|
76
|
-
closeWindow(): Promise<void>;
|
|
77
|
-
consumeAndShareCard(options: WxType.IconsumeAndShareCard): Promise<void>;
|
|
78
|
-
downloadImage(options: WxType.IdownloadImage): Promise<void>;
|
|
79
|
-
downloadVoice(options: WxType.IupdownloadVoice): Promise<void>;
|
|
80
|
-
getLocalImgData(options: WxType.IgetLocalImgData): Promise<void>;
|
|
81
|
-
getLocation(options: WxType.IgetLocation): Promise<void>;
|
|
82
|
-
getNetworkType(options: WxType.IgetNetworkType): Promise<void>;
|
|
83
|
-
hideAllNonBaseMenuItem(): Promise<void>;
|
|
84
|
-
hideMenuItems(options: WxType.IhideMenuItems): Promise<void>;
|
|
85
|
-
hideOptionMenu(): Promise<void>;
|
|
86
|
-
onMenuShareAppMessage(options: WxType.IonMenuShareAppMessage): Promise<void>;
|
|
87
|
-
onMenuShareQQ(options: WxType.IonMenuShareQQ): Promise<void>;
|
|
88
|
-
onMenuShareQZone(options: WxType.IonMenuShareQZone): Promise<void>;
|
|
89
|
-
onMenuShareTimeline(options: WxType.IonMenuShareTimeline): Promise<void>;
|
|
90
|
-
onMenuShareWeibo(options: WxType.IonMenuShareWeibo): Promise<void>;
|
|
91
|
-
onSearchBeacons(options: WxType.IonSearchBeacons): Promise<void>;
|
|
92
|
-
onVoicePlayEnd(options: WxType.IonVoicePlayEnd): Promise<void>;
|
|
93
|
-
onVoiceRecordEnd(options: WxType.IonVoiceRecordEnd): Promise<void>;
|
|
94
|
-
openCard(options: WxType.IopenCard): Promise<void>;
|
|
95
|
-
openLocation(options: WxType.IopenLocation): Promise<void>;
|
|
96
|
-
openProductSpecificView(options: WxType.IopenProductSpecificView): Promise<void>;
|
|
97
|
-
pauseVoice(options: WxType.IplaypausestopVoice): Promise<void>;
|
|
98
|
-
playVoice(options: WxType.IplaypausestopVoice): Promise<void>;
|
|
99
|
-
previewImage(options: WxType.IpreviewImage): Promise<void>;
|
|
100
|
-
scanQRCode(options: WxType.IscanQRCode): Promise<void>;
|
|
101
|
-
showAllNonBaseMenuItem(): Promise<void>;
|
|
102
|
-
showMenuItems(options: WxType.IshowMenuItems): Promise<void>;
|
|
103
|
-
showOptionMenu(): Promise<void>;
|
|
104
|
-
startRecord(): Promise<void>;
|
|
105
|
-
startSearchBeacons(options: WxType.IstartSearchBeacons): Promise<void>;
|
|
106
|
-
stopRecord(options: WxType.IstopRecord): Promise<void>;
|
|
107
|
-
stopSearchBeacons(options: WxType.IstopSearchBeacons): Promise<void>;
|
|
108
|
-
stopVoice(options: WxType.IplaypausestopVoice): Promise<void>;
|
|
109
|
-
translateVoice(options: WxType.ItranslateVoice): Promise<void>;
|
|
110
|
-
uploadImage(options: WxType.IuploadImage): Promise<void>;
|
|
111
|
-
uploadVoice(options: WxType.IupdownloadVoice): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* @description WechatJssdk Api 封装,与 [jssdk 文档](https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html) 保持一致,主要以下改动
|
|
61
|
+
* @description 内置请求,读取 config 配置,初始化自动调用 wx.config
|
|
62
|
+
* @description 所有 api 的 promise 化处理(仅等待 wx.ready)
|
|
63
|
+
* @description 简易化初始化构建,config 处理
|
|
64
|
+
* @description 可指定加载 jssdk 版本(默认 1.3.0)
|
|
65
|
+
* @template `const wxJssdk = new WechatJssdk({env, config})`
|
|
66
|
+
*/
|
|
67
|
+
declare class WechatJssdk extends WechatJssdkHelper {
|
|
68
|
+
constructor(options: WechatJssdkOptions);
|
|
69
|
+
updateAppMessageShareData(options: WxType.IonMenuShareAppMessage): Promise<void>;
|
|
70
|
+
updateTimelineShareData(options: WxType.IonMenuShareAppMessage): Promise<void>;
|
|
71
|
+
addCard(): Promise<void>;
|
|
72
|
+
checkJsApi(options: WxType.IcheckJsApi): Promise<void>;
|
|
73
|
+
chooseCard(options: WxType.IchooseCard): Promise<void>;
|
|
74
|
+
chooseImage(options: WxType.IchooseImage): Promise<void>;
|
|
75
|
+
chooseWXPay(options: WxType.IchooseWXPay): Promise<void>;
|
|
76
|
+
closeWindow(): Promise<void>;
|
|
77
|
+
consumeAndShareCard(options: WxType.IconsumeAndShareCard): Promise<void>;
|
|
78
|
+
downloadImage(options: WxType.IdownloadImage): Promise<void>;
|
|
79
|
+
downloadVoice(options: WxType.IupdownloadVoice): Promise<void>;
|
|
80
|
+
getLocalImgData(options: WxType.IgetLocalImgData): Promise<void>;
|
|
81
|
+
getLocation(options: WxType.IgetLocation): Promise<void>;
|
|
82
|
+
getNetworkType(options: WxType.IgetNetworkType): Promise<void>;
|
|
83
|
+
hideAllNonBaseMenuItem(): Promise<void>;
|
|
84
|
+
hideMenuItems(options: WxType.IhideMenuItems): Promise<void>;
|
|
85
|
+
hideOptionMenu(): Promise<void>;
|
|
86
|
+
onMenuShareAppMessage(options: WxType.IonMenuShareAppMessage): Promise<void>;
|
|
87
|
+
onMenuShareQQ(options: WxType.IonMenuShareQQ): Promise<void>;
|
|
88
|
+
onMenuShareQZone(options: WxType.IonMenuShareQZone): Promise<void>;
|
|
89
|
+
onMenuShareTimeline(options: WxType.IonMenuShareTimeline): Promise<void>;
|
|
90
|
+
onMenuShareWeibo(options: WxType.IonMenuShareWeibo): Promise<void>;
|
|
91
|
+
onSearchBeacons(options: WxType.IonSearchBeacons): Promise<void>;
|
|
92
|
+
onVoicePlayEnd(options: WxType.IonVoicePlayEnd): Promise<void>;
|
|
93
|
+
onVoiceRecordEnd(options: WxType.IonVoiceRecordEnd): Promise<void>;
|
|
94
|
+
openCard(options: WxType.IopenCard): Promise<void>;
|
|
95
|
+
openLocation(options: WxType.IopenLocation): Promise<void>;
|
|
96
|
+
openProductSpecificView(options: WxType.IopenProductSpecificView): Promise<void>;
|
|
97
|
+
pauseVoice(options: WxType.IplaypausestopVoice): Promise<void>;
|
|
98
|
+
playVoice(options: WxType.IplaypausestopVoice): Promise<void>;
|
|
99
|
+
previewImage(options: WxType.IpreviewImage): Promise<void>;
|
|
100
|
+
scanQRCode(options: WxType.IscanQRCode): Promise<void>;
|
|
101
|
+
showAllNonBaseMenuItem(): Promise<void>;
|
|
102
|
+
showMenuItems(options: WxType.IshowMenuItems): Promise<void>;
|
|
103
|
+
showOptionMenu(): Promise<void>;
|
|
104
|
+
startRecord(): Promise<void>;
|
|
105
|
+
startSearchBeacons(options: WxType.IstartSearchBeacons): Promise<void>;
|
|
106
|
+
stopRecord(options: WxType.IstopRecord): Promise<void>;
|
|
107
|
+
stopSearchBeacons(options: WxType.IstopSearchBeacons): Promise<void>;
|
|
108
|
+
stopVoice(options: WxType.IplaypausestopVoice): Promise<void>;
|
|
109
|
+
translateVoice(options: WxType.ItranslateVoice): Promise<void>;
|
|
110
|
+
uploadImage(options: WxType.IuploadImage): Promise<void>;
|
|
111
|
+
uploadVoice(options: WxType.IupdownloadVoice): Promise<void>;
|
|
112
112
|
}
|
|
113
113
|
|
|
114
114
|
export { WechatJssdk };
|
|
@@ -0,0 +1,253 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
(() => {
|
|
3
|
+
// ../util-core/src/util/noop.ts
|
|
4
|
+
var noop = () => {
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
// src/internal/load_script.ts
|
|
8
|
+
function loadScript(source, onLoaded = noop, options = {}) {
|
|
9
|
+
const {
|
|
10
|
+
type = "text/javascript",
|
|
11
|
+
async = true,
|
|
12
|
+
crossOrigin,
|
|
13
|
+
referrerPolicy,
|
|
14
|
+
noModule,
|
|
15
|
+
defer,
|
|
16
|
+
waitForScriptLoad = true
|
|
17
|
+
} = options;
|
|
18
|
+
return new Promise((resolve, reject) => {
|
|
19
|
+
let shouldAppend = false;
|
|
20
|
+
let element = document.querySelector(`script[src="${source}"]`);
|
|
21
|
+
if (!element) {
|
|
22
|
+
element = document.createElement("script");
|
|
23
|
+
element.type = type;
|
|
24
|
+
element.async = async;
|
|
25
|
+
element.src = source;
|
|
26
|
+
if (defer)
|
|
27
|
+
element.defer = defer;
|
|
28
|
+
if (crossOrigin)
|
|
29
|
+
element.crossOrigin = crossOrigin;
|
|
30
|
+
if (noModule)
|
|
31
|
+
element.noModule = noModule;
|
|
32
|
+
if (referrerPolicy)
|
|
33
|
+
element.referrerPolicy = referrerPolicy;
|
|
34
|
+
shouldAppend = true;
|
|
35
|
+
} else if (Object.hasOwn(element.dataset, "loaded")) {
|
|
36
|
+
resolve(element);
|
|
37
|
+
}
|
|
38
|
+
element.addEventListener("error", (event) => reject(event));
|
|
39
|
+
element.addEventListener("abort", (event) => reject(event));
|
|
40
|
+
element.addEventListener("load", () => {
|
|
41
|
+
element.dataset.loaded = "true";
|
|
42
|
+
onLoaded(element);
|
|
43
|
+
resolve(element);
|
|
44
|
+
});
|
|
45
|
+
if (shouldAppend)
|
|
46
|
+
element = document.head.appendChild(element);
|
|
47
|
+
if (!waitForScriptLoad)
|
|
48
|
+
resolve(element);
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// src/helper.ts
|
|
53
|
+
var WechatJssdkHelper = class {
|
|
54
|
+
version;
|
|
55
|
+
isReady = false;
|
|
56
|
+
requestConfig;
|
|
57
|
+
loadPromise;
|
|
58
|
+
configPromise;
|
|
59
|
+
readyPromise;
|
|
60
|
+
loadJssdk() {
|
|
61
|
+
const scriptUrl = `https://res.wx.qq.com/open/js/jweixin-${this.version}.js`;
|
|
62
|
+
this.loadPromise = loadScript(scriptUrl).then(() => {
|
|
63
|
+
this.loadPromise = void 0;
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
constructor(options) {
|
|
67
|
+
const { immediate = true, version, requestConfig } = options;
|
|
68
|
+
this.version = version || "1.3.0";
|
|
69
|
+
this.requestConfig = requestConfig;
|
|
70
|
+
this.loadJssdk();
|
|
71
|
+
if (immediate)
|
|
72
|
+
this.config();
|
|
73
|
+
}
|
|
74
|
+
async config() {
|
|
75
|
+
if (this.configPromise)
|
|
76
|
+
return this.configPromise;
|
|
77
|
+
if (this.loadPromise)
|
|
78
|
+
await this.loadPromise;
|
|
79
|
+
this.configPromise = (async () => {
|
|
80
|
+
wx.config(await this.requestConfig());
|
|
81
|
+
})();
|
|
82
|
+
return this.configPromise;
|
|
83
|
+
}
|
|
84
|
+
async ready() {
|
|
85
|
+
if (this.readyPromise)
|
|
86
|
+
return this.readyPromise;
|
|
87
|
+
if (this.loadPromise)
|
|
88
|
+
await this.loadPromise;
|
|
89
|
+
if (this.isReady)
|
|
90
|
+
return;
|
|
91
|
+
this.readyPromise = new Promise((resolve, reject) => {
|
|
92
|
+
wx.ready(() => {
|
|
93
|
+
this.isReady = true;
|
|
94
|
+
this.readyPromise = void 0;
|
|
95
|
+
resolve();
|
|
96
|
+
});
|
|
97
|
+
wx.error((error) => {
|
|
98
|
+
this.isReady = false;
|
|
99
|
+
this.readyPromise = void 0;
|
|
100
|
+
reject(error);
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
return this.readyPromise;
|
|
104
|
+
}
|
|
105
|
+
async error() {
|
|
106
|
+
return this.ready().catch((error) => error);
|
|
107
|
+
}
|
|
108
|
+
async implement(key, options) {
|
|
109
|
+
if (this.configPromise)
|
|
110
|
+
await this.configPromise;
|
|
111
|
+
await this.ready();
|
|
112
|
+
wx[key](options);
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
// src/index.ts
|
|
117
|
+
var WechatJssdk = class extends WechatJssdkHelper {
|
|
118
|
+
constructor(options) {
|
|
119
|
+
super(options);
|
|
120
|
+
}
|
|
121
|
+
// --- 1.4.0 API start ---
|
|
122
|
+
updateAppMessageShareData(options) {
|
|
123
|
+
return this.implement("updateAppMessageShareData", options);
|
|
124
|
+
}
|
|
125
|
+
updateTimelineShareData(options) {
|
|
126
|
+
return this.implement("updateTimelineShareData", options);
|
|
127
|
+
}
|
|
128
|
+
// --- 1.4.0 API end ---
|
|
129
|
+
addCard() {
|
|
130
|
+
return this.implement("addCard");
|
|
131
|
+
}
|
|
132
|
+
checkJsApi(options) {
|
|
133
|
+
return this.implement("checkJsApi", options);
|
|
134
|
+
}
|
|
135
|
+
chooseCard(options) {
|
|
136
|
+
return this.implement("chooseCard", options);
|
|
137
|
+
}
|
|
138
|
+
chooseImage(options) {
|
|
139
|
+
return this.implement("chooseImage", options);
|
|
140
|
+
}
|
|
141
|
+
chooseWXPay(options) {
|
|
142
|
+
return this.implement("chooseWXPay", options);
|
|
143
|
+
}
|
|
144
|
+
closeWindow() {
|
|
145
|
+
return this.implement("closeWindow");
|
|
146
|
+
}
|
|
147
|
+
consumeAndShareCard(options) {
|
|
148
|
+
return this.implement("consumeAndShareCard", options);
|
|
149
|
+
}
|
|
150
|
+
downloadImage(options) {
|
|
151
|
+
return this.implement("downloadImage", options);
|
|
152
|
+
}
|
|
153
|
+
downloadVoice(options) {
|
|
154
|
+
return this.implement("downloadVoice", options);
|
|
155
|
+
}
|
|
156
|
+
getLocalImgData(options) {
|
|
157
|
+
return this.implement("getLocalImgData", options);
|
|
158
|
+
}
|
|
159
|
+
getLocation(options) {
|
|
160
|
+
return this.implement("getLocation", options);
|
|
161
|
+
}
|
|
162
|
+
getNetworkType(options) {
|
|
163
|
+
return this.implement("getNetworkType", options);
|
|
164
|
+
}
|
|
165
|
+
hideAllNonBaseMenuItem() {
|
|
166
|
+
return this.implement("hideAllNonBaseMenuItem");
|
|
167
|
+
}
|
|
168
|
+
hideMenuItems(options) {
|
|
169
|
+
return this.implement("hideMenuItems", options);
|
|
170
|
+
}
|
|
171
|
+
hideOptionMenu() {
|
|
172
|
+
return this.implement("hideOptionMenu");
|
|
173
|
+
}
|
|
174
|
+
onMenuShareAppMessage(options) {
|
|
175
|
+
return this.implement("onMenuShareAppMessage", options);
|
|
176
|
+
}
|
|
177
|
+
onMenuShareQQ(options) {
|
|
178
|
+
return this.implement("onMenuShareQQ", options);
|
|
179
|
+
}
|
|
180
|
+
onMenuShareQZone(options) {
|
|
181
|
+
return this.implement("onMenuShareQZone", options);
|
|
182
|
+
}
|
|
183
|
+
onMenuShareTimeline(options) {
|
|
184
|
+
return this.implement("onMenuShareTimeline", options);
|
|
185
|
+
}
|
|
186
|
+
onMenuShareWeibo(options) {
|
|
187
|
+
return this.implement("onMenuShareWeibo", options);
|
|
188
|
+
}
|
|
189
|
+
onSearchBeacons(options) {
|
|
190
|
+
return this.implement("onSearchBeacons", options);
|
|
191
|
+
}
|
|
192
|
+
onVoicePlayEnd(options) {
|
|
193
|
+
return this.implement("onVoicePlayEnd", options);
|
|
194
|
+
}
|
|
195
|
+
onVoiceRecordEnd(options) {
|
|
196
|
+
return this.implement("onVoiceRecordEnd", options);
|
|
197
|
+
}
|
|
198
|
+
openCard(options) {
|
|
199
|
+
return this.implement("openCard", options);
|
|
200
|
+
}
|
|
201
|
+
openLocation(options) {
|
|
202
|
+
return this.implement("openLocation", options);
|
|
203
|
+
}
|
|
204
|
+
openProductSpecificView(options) {
|
|
205
|
+
return this.implement("openProductSpecificView", options);
|
|
206
|
+
}
|
|
207
|
+
pauseVoice(options) {
|
|
208
|
+
return this.implement("pauseVoice", options);
|
|
209
|
+
}
|
|
210
|
+
playVoice(options) {
|
|
211
|
+
return this.implement("playVoice", options);
|
|
212
|
+
}
|
|
213
|
+
previewImage(options) {
|
|
214
|
+
return this.implement("previewImage", options);
|
|
215
|
+
}
|
|
216
|
+
scanQRCode(options) {
|
|
217
|
+
return this.implement("scanQRCode", options);
|
|
218
|
+
}
|
|
219
|
+
showAllNonBaseMenuItem() {
|
|
220
|
+
return this.implement("showAllNonBaseMenuItem");
|
|
221
|
+
}
|
|
222
|
+
showMenuItems(options) {
|
|
223
|
+
return this.implement("showMenuItems", options);
|
|
224
|
+
}
|
|
225
|
+
showOptionMenu() {
|
|
226
|
+
return this.implement("showOptionMenu");
|
|
227
|
+
}
|
|
228
|
+
startRecord() {
|
|
229
|
+
return this.implement("startRecord");
|
|
230
|
+
}
|
|
231
|
+
startSearchBeacons(options) {
|
|
232
|
+
return this.implement("startSearchBeacons", options);
|
|
233
|
+
}
|
|
234
|
+
stopRecord(options) {
|
|
235
|
+
return this.implement("stopRecord", options);
|
|
236
|
+
}
|
|
237
|
+
stopSearchBeacons(options) {
|
|
238
|
+
return this.implement("stopSearchBeacons", options);
|
|
239
|
+
}
|
|
240
|
+
stopVoice(options) {
|
|
241
|
+
return this.implement("stopVoice", options);
|
|
242
|
+
}
|
|
243
|
+
translateVoice(options) {
|
|
244
|
+
return this.implement("translateVoice", options);
|
|
245
|
+
}
|
|
246
|
+
uploadImage(options) {
|
|
247
|
+
return this.implement("uploadImage", options);
|
|
248
|
+
}
|
|
249
|
+
uploadVoice(options) {
|
|
250
|
+
return this.implement("uploadVoice", options);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
})();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// src/internal/load_script.ts
|
|
2
|
-
import noop from "
|
|
2
|
+
import { noop } from "@hairy/utils";
|
|
3
3
|
function loadScript(source, onLoaded = noop, options = {}) {
|
|
4
4
|
const {
|
|
5
5
|
type = "text/javascript",
|
|
@@ -46,8 +46,19 @@ function loadScript(source, onLoaded = noop, options = {}) {
|
|
|
46
46
|
|
|
47
47
|
// src/helper.ts
|
|
48
48
|
var WechatJssdkHelper = class {
|
|
49
|
+
version;
|
|
50
|
+
isReady = false;
|
|
51
|
+
requestConfig;
|
|
52
|
+
loadPromise;
|
|
53
|
+
configPromise;
|
|
54
|
+
readyPromise;
|
|
55
|
+
loadJssdk() {
|
|
56
|
+
const scriptUrl = `https://res.wx.qq.com/open/js/jweixin-${this.version}.js`;
|
|
57
|
+
this.loadPromise = loadScript(scriptUrl).then(() => {
|
|
58
|
+
this.loadPromise = void 0;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
49
61
|
constructor(options) {
|
|
50
|
-
this.isReady = false;
|
|
51
62
|
const { immediate = true, version, requestConfig } = options;
|
|
52
63
|
this.version = version || "1.3.0";
|
|
53
64
|
this.requestConfig = requestConfig;
|
|
@@ -55,12 +66,6 @@ var WechatJssdkHelper = class {
|
|
|
55
66
|
if (immediate)
|
|
56
67
|
this.config();
|
|
57
68
|
}
|
|
58
|
-
loadJssdk() {
|
|
59
|
-
const scriptUrl = `https://res.wx.qq.com/open/js/jweixin-${this.version}.js`;
|
|
60
|
-
this.loadPromise = loadScript(scriptUrl).then(() => {
|
|
61
|
-
this.loadPromise = void 0;
|
|
62
|
-
});
|
|
63
|
-
}
|
|
64
69
|
async config() {
|
|
65
70
|
if (this.configPromise)
|
|
66
71
|
return this.configPromise;
|
package/package.json
CHANGED
|
@@ -1,31 +1,43 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hairy/wechat-jssdk",
|
|
3
|
-
"
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "1.6.0",
|
|
5
|
+
"description": "Library for Wechat Jssdk",
|
|
6
|
+
"author": "Hairyf <wwu710632@gmail.com>",
|
|
4
7
|
"license": "MIT",
|
|
5
|
-
"
|
|
8
|
+
"funding": "https://github.com/sponsors/hairyf",
|
|
9
|
+
"homepage": "https://github.com/hairyf/hairylib#readme",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "git+https://github.com/hairyf/hairylib.git"
|
|
13
|
+
},
|
|
14
|
+
"bugs": "https://github.com/hairyf/hairylib/issues",
|
|
15
|
+
"keywords": [],
|
|
16
|
+
"sideEffects": false,
|
|
17
|
+
"main": "./dist/index.js",
|
|
6
18
|
"publishConfig": {
|
|
7
|
-
"jsdelivr": "./dist/index.
|
|
19
|
+
"jsdelivr": "./dist/index.global.js"
|
|
8
20
|
},
|
|
9
21
|
"files": [
|
|
10
22
|
"dist"
|
|
11
23
|
],
|
|
12
24
|
"dependencies": {
|
|
13
|
-
"@
|
|
14
|
-
"lodash": "^4"
|
|
25
|
+
"@hairy/utils": "1.6.0"
|
|
15
26
|
},
|
|
16
27
|
"devDependencies": {
|
|
17
|
-
"@types/
|
|
18
|
-
"jweixin": "^1.0.0"
|
|
28
|
+
"@types/jweixin": "^1.0.8"
|
|
19
29
|
},
|
|
20
30
|
"scripts": {
|
|
21
|
-
"build": "
|
|
31
|
+
"build": "tsup",
|
|
32
|
+
"dev": "tsup --watch",
|
|
33
|
+
"start": "tsx src/index.ts"
|
|
22
34
|
},
|
|
23
|
-
"module": "./dist/index.
|
|
35
|
+
"module": "./dist/index.js",
|
|
24
36
|
"types": "./dist/index.d.ts",
|
|
25
|
-
"unpkg": "./dist/index.
|
|
37
|
+
"unpkg": "./dist/index.global.js",
|
|
26
38
|
"exports": {
|
|
27
39
|
".": {
|
|
28
|
-
"import": "./dist/index.
|
|
40
|
+
"import": "./dist/index.js",
|
|
29
41
|
"require": "./dist/index.cjs",
|
|
30
42
|
"types": "./dist/index.d.ts"
|
|
31
43
|
},
|