Compare commits

..

28 Commits

Author SHA1 Message Date
阎曦
4f3339597b update version to 1.6.5 2023-11-22 01:16:43 +08:00
阎曦
4cae61fdec Merge branch 'master' of github.com:yanxi-me/weixin-js-sdk 2023-11-22 01:15:36 +08:00
阎曦
2608bc3012
Merge pull request #57 from lamprose/master
fix:上传下载语音参数错误
2023-11-22 01:15:25 +08:00
lamprose
e191d38838
fix:上传下载语音参数错误 2023-11-20 14:09:20 +08:00
阎曦
1a01edab62 发布 1.6.4, 完善 ts 定义, 补全了开放标签列表 2023-11-17 23:43:17 +08:00
阎曦
fd2a4f2f0d
Merge pull request #56 from woshiydh08/dev
补全开放标签列表
2023-11-17 23:39:24 +08:00
totoro
678752eae8 fix: 补全开放标签列表 2023-11-16 18:10:33 +08:00
yanxi
00d469af93 修改文档 2023-10-26 23:13:51 +08:00
Yanxi
63405a45f4
add LICENSE.
Signed-off-by: Yanxi <5554591+yanxi-me@user.noreply.gitee.com>
2023-10-20 15:05:14 +00:00
yanxi
90a2a06507 更新 Readme, 升级到 1.6.2 2023-10-18 00:10:51 +08:00
yanxi
a31e92506f update package.json 2023-10-17 22:29:34 +08:00
yanxi
3f26c90482 增加 typescript 定义文件 2023-10-17 22:27:17 +08:00
yanxi
a895af9f99 增加 window 对象检查, 并保证每次都返回正确的 wx 对象, 避免重复引用时返回 undefined 2023-10-17 22:21:17 +08:00
yanxi
0d38e1dcca 更新 index.original.js from https://res.wx.qq.com/open/js/jweixin-1.6.0.js 2023-10-17 21:27:32 +08:00
vanbolee
9b8ce680b1 更新微信官方sdk1.6.0 2020-03-19 14:32:23 +08:00
YanXi
84bd55d1df update version to weixin-js-sdk@1.4.0-test 2018-09-28 17:17:52 +08:00
Yanxi
93bc926079
Merge pull request #27 from HadiChen/master
更新微信官方sdk1.4.0
2018-09-28 17:07:46 +08:00
陈华狄
b9ae7e21e8 更新微信官方sdk1.4.0 2018-09-22 17:04:57 +08:00
YanXi
b1f5275265 1.3.3 2018-07-19 21:56:43 +08:00
Yanxi
9b589edfb9
Merge pull request #19 from liupl/fixWxBug
修复选择图片后提示:wx is not define
2018-07-19 21:54:44 +08:00
liupl
8f436f2f26 修改wx为N 2018-05-03 18:56:32 +08:00
Yan Xi
43f6346ae1 update README 2018-02-07 12:01:02 +08:00
Yan Xi
f89e7e23fb 更新官方使用说明链接 2018-02-07 11:50:59 +08:00
Yan Xi
3d0d7fd38a update version to 1.3.2 2018-02-07 11:38:57 +08:00
Yan Xi
595171818b add .vscode to .gitignore 2018-02-07 11:29:13 +08:00
Yanxi
d4312faefd
Merge pull request #15 from LazyNeo/master
jweixin-jssdk update to 1.3.2
2018-02-07 11:21:32 +08:00
NeoPasser
54fb0b360a 修改this为window 2018-02-06 15:49:32 +08:00
NeoPasser
fa53277dcc jweixin-jssdk update to 1.3.2 2018-02-06 15:19:39 +08:00
8 changed files with 2433 additions and 479 deletions

2
.gitignore vendored
View File

@ -1,2 +1,2 @@
.idea .idea
.vscode

1
.npmignore Normal file
View File

@ -0,0 +1 @@
index.original.js

21
LICENSE Normal file
View File

@ -0,0 +1,21 @@
MIT License
Copyright (c) 2023 Yanxi
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

View File

@ -1,20 +1,36 @@
微信官方 js-sdk 微信官方 js-sdk
---- ----
说明: 仅将官方 js-sdk 发布到 npm便于 browserify 使用 说明: 仅将官方 js-sdk 发布到 npm支持 CommonJS便于 browserify, webpack 等直接使用,支持 TypeScript。
js源码: https://res.wx.qq.com/open/js/jweixin-1.2.0.js
官方使用说明: https://mp.weixin.qq.com/wiki 微信网页开发 - iOS 网页开发适配指南 官方 JS 源码: https://res.wx.qq.com/open/js/jweixin-1.6.0.js
官方使用说明: https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html
安装: 安装:
```shell
npm install weixin-js-sdk npm install weixin-js-sdk
```
使用: 使用:
```javascript
// commonjs
var wx = require('weixin-js-sdk');
var wx = require('weixin-js-sdk'); // es module
import wx from 'weixin-js-sdk'
```
### Old version ### Old versions
[1.0.0](https://github.com/yanxi-me/weixin-js-sdk/tree/1.0.0) * [1.0.0](https://github.com/yanxi123-com/weixin-js-sdk/tree/1.0.0)
* [1.2.0](https://github.com/yanxi123-com/weixin-js-sdk/tree/1.2.0)
### 个人主页
* [https://yanxi123.com/](https://yanxi123.com/)
### 感谢
TypeScript 定义文件来自 [wx-jssdk-ts](https://github.com/zhaoky/wx-jssdk-ts/blob/master/index.d.ts)

601
index.d.ts vendored Normal file
View File

@ -0,0 +1,601 @@
// Type definitions for weixin jssdk 1.6.0
// Project: https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace wx {
type ImageSizeType = "original" | "compressed";
type ImageSourceType = "album" | "camera";
type VideoSourceType = "album" | "camera";
type ApiMethod =
| "onMenuShareTimeline"
| "onMenuShareAppMessage"
| "onMenuShareQQ"
| "onMenuShareWeibo"
| "onMenuShareQZone"
| "updateAppMessageShareData"
| "updateTimelineShareData"
| "startRecord"
| "stopRecord"
| "onVoiceRecordEnd"
| "playVoice"
| "pauseVoice"
| "stopVoice"
| "onVoicePlayEnd"
| "uploadVoice"
| "downloadVoice"
| "chooseImage"
| "previewImage"
| "uploadImage"
| "downloadImage"
| "translateVoice"
| "getNetworkType"
| "openLocation"
| "getLocation"
| "hideOptionMenu"
| "showOptionMenu"
| "hideMenuItems"
| "showMenuItems"
| "hideAllNonBaseMenuItem"
| "showAllNonBaseMenuItem"
| "closeWindow"
| "scanQRCode"
| "chooseWXPay"
| "openProductSpecificView"
| "addCard"
| "chooseCard"
| "openCard";
// 所有JS接口列表
type jsApiList = ApiMethod[];
// 开放标签列表
// https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_Open_Tag.html
type openTag = "wx-open-launch-weapp" | "wx-open-launch-app" | "wx-open-subscribe" | "wx-open-audio"
type openTagList = openTag[];
// 所有菜单项列表
// 基本类
type menuBase =
| "menuItem:exposeArticle" // 举报
| "menuItem:setFont" // 调整字体
| "menuItem:dayMode" // 日间模式
| "menuItem:nightMode" // 夜间模式
| "menuItem:refresh" // 刷新
| "menuItem:profile" // 查看公众号(已添加)
| "menuItem:addContact"; // 查看公众号(未添加)
// 传播类
type menuShare =
| "menuItem:share:appMessage" // 发送给朋友
| "menuItem:share:timeline" // 分享到朋友圈
| "menuItem:share:qq" // 分享到QQ
| "menuItem:share:weiboApp" // 分享到Weibo
| "menuItem:favorite" // 收藏
| "menuItem:share:facebook" // 分享到FB
| "menuItem:share:QZone"; // 分享到 QQ 空间
// 保护类
type menuProtected =
| "menuItem:editTag" // 编辑标签
| "menuItem:delete" // 删除
| "menuItem:copyUrl" // 复制链接
| "menuItem:originPage" // 原网页
| "menuItem:readMode" // 阅读模式
| "menuItem:openWithQQBrowser" // 在QQ浏览器中打开
| "menuItem:openWithSafari" // 在Safari中打开
| "menuItem:share:email" // 邮件
| "menuItem:share:brand"; // 一些特殊公众号
type menuList = Array<menuBase | menuProtected | menuShare>;
function config(conf: {
debug?: boolean; // 开启调试模式,调用的所有api的返回值会在客户端alert出来若要查看传入的参数可以在pc端打开参数信息会通过log打出仅在pc端时才会打印。
appId: string; // 必填,公众号的唯一标识
timestamp: number; // 必填,生成签名的时间戳
nonceStr: string; // 必填,生成签名的随机串
signature: string; // 必填签名见附录1
jsApiList?: jsApiList; // 必填需要使用的JS接口列表所有JS接口列表见附录2
openTagList?: openTagList;
}): void;
interface Resouce {
localId: string;
}
interface BaseParams {
success?(...args: any[]): void;
/** 接口调用失败的回调函数 */
fail?(...args: any[]): void;
/** 接口取消调用的回调函数 */
cancel?(...args: any[]): void;
/** 接口调用结束的回调函数(调用成功、失败都会执行) */
complete?(...args: any[]): void;
}
function ready(fn: () => void): void;
function error(fn: (err: { errMsg: string }) => void): void;
interface IcheckJsApi extends BaseParams {
jsApiList: jsApiList; // 需要检测的JS接口列表所有JS接口列表见附录2,
// 以键值对的形式返回可用的api值true不可用为false
// 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
success(res: {
checkResult: { [api: string]: boolean };
errMsg: string;
}): void;
}
/**
* JS接口
* checkJsApi接口是客户端6.0.2使checkJsApi来检测
*/
function checkJsApi(params: IcheckJsApi): void;
interface IonMenuShareTimeline extends BaseParams {
title: string; // 分享标题
link: string; // 分享链接
imgUrl: string; // 分享图标
// 用户确认分享后执行的回调函数
success(): void;
// 用户取消分享后执行的回调函数
cancel(): void;
}
/*=============================基础接口================================*/
/**
*
*/
function onMenuShareTimeline(params: IonMenuShareTimeline): void;
interface IonMenuShareAppMessage extends BaseParams {
title: string; // 分享标题
desc: string; // 分享描述
link: string; // 分享链接
imgUrl: string; // 分享图标
type?: "music" | "video或link" | "link"; // 分享类型,music、video或link不填默认为link
dataUrl?: string; // 如果type是music或video则要提供数据链接默认为空
// 用户确认分享后执行的回调函数
success(): void;
// 用户取消分享后执行的回调函数
cancel(): void;
}
/**
*
*/
function onMenuShareAppMessage(params: IonMenuShareAppMessage): void;
interface IonMenuShareQQ extends BaseParams {
title: string; // 分享标题
desc: string; // 分享描述
link: string; // 分享链接
imgUrl: string; // 分享图标
// 用户确认分享后执行的回调函数
success(): void;
// 用户取消分享后执行的回调函数
cancel(): void;
}
/**
* QQ
*/
function onMenuShareQQ(params: IonMenuShareQQ): void;
interface IonMenuShareWeibo extends BaseParams {
title: string; // 分享标题
desc: string; // 分享描述
link: string; // 分享链接
imgUrl: string; // 分享图标
// 用户确认分享后执行的回调函数
success(): void;
// 用户取消分享后执行的回调函数
cancel(): void;
}
/**
*
*/
function onMenuShareWeibo(params: IonMenuShareWeibo): void;
interface IonMenuShareQZone extends BaseParams {
title: string; // 分享标题
desc: string; // 分享描述
link: string; // 分享链接
imgUrl: string; // 分享图标
// 用户确认分享后执行的回调函数
success(): void;
// 用户取消分享后执行的回调函数
cancel(): void;
}
/**
* QQ空间
*/
function onMenuShareQZone(params: IonMenuShareQZone): void;
interface IupdateAppMessageShareData extends BaseParams {
title: string; // 分享标题
desc: string; // 分享描述
link: string; // 分享链接
imgUrl: string; // 分享图标
// 用户确认分享后执行的回调函数
success(): void;
}
/**
* QQ
*/
function updateAppMessageShareData(params: IupdateAppMessageShareData): void;
interface IupdateTimelineShareData extends BaseParams {
title: string; // 分享标题
link: string; // 分享链接
imgUrl: string; // 分享图标
// 用户确认分享后执行的回调函数
success(): void;
}
/**
* QQ空间
*/
function updateTimelineShareData(params: IupdateTimelineShareData): void;
/*=============================基础接口================================*/
/*=============================图像接口================================*/
interface IchooseImage extends BaseParams {
/** 最多可以选择的图片张数默认9 */
count?: number;
/** original 原图compressed 压缩图,默认二者都有 */
sizeType?: ImageSizeType[];
/** album 从相册选图camera 使用相机,默认二者都有 */
sourceType?: ImageSourceType[];
/** 成功则返回图片的本地文件路径列表 tempFilePaths */
success(res: {
sourceType: string; // weixin album camera
localIds: string[];
errMsg: string;
}): void;
cancel(): void;
}
/**
* 使
*/
function chooseImage(params: IchooseImage): void;
interface IpreviewImage extends BaseParams {
current: string; // 当前显示图片的http链接
urls: string[]; // 需要预览的图片http链接列表
}
/**
*
*/
function previewImage(params: IpreviewImage): void;
interface IuploadResource extends BaseParams {
localId: string; // 需要上传的图片的本地ID由chooseImage接口获得
isShowProgressTips: number; // 默认为1显示进度提示
// 返回图片的服务器端ID
success(res: { serverId: string }): void;
}
/**
*
*/
function uploadImage(params: IuploadResource): void;
interface IdownloadResource extends BaseParams {
serverId: string; // 需要下载的图片的服务器端ID由uploadImage接口获得
isShowProgressTips: number; // 默认为1显示进度提示
// 返回图片下载后的本地ID
success(res: Resouce): void;
}
/**
*
*/
function downloadImage(params: IdownloadResource): void;
interface IgetLocalImgData extends BaseParams {
localId: string; // 图片的localID
// localData是图片的base64数据可以用img标签显示
success(res: { localData: string }): void;
}
/**
*
*/
function getLocalImgData(params: IgetLocalImgData): void;
/*=============================图像接口================================*/
/*=============================音频接口================================*/
/**
*
*/
function startRecord(): void;
interface IstopRecord extends BaseParams {
success(res: Resouce): void;
}
/**
*
*/
function stopRecord(params: IstopRecord): void;
interface IonVoiceRecordEnd extends BaseParams {
// 录音时间超过一分钟没有停止的时候会执行 complete 回调
complete(res: Resouce): void;
}
/**
*
*/
function onVoiceRecordEnd(params: IonVoiceRecordEnd): void;
interface IplaypausestopVoice extends BaseParams {
localId: string; // 需要播放的音频的本地ID由stopRecord接口获得
}
/**
*
*/
function playVoice(params: IplaypausestopVoice): void;
/**
*
*/
function pauseVoice(params: IplaypausestopVoice): void;
/**
*
*/
function stopVoice(params: IplaypausestopVoice): void;
interface IonVoicePlayEnd extends BaseParams {
success(res: Resouce): void;
}
/**
*
*/
function onVoicePlayEnd(params: IonVoicePlayEnd): void;
/**
*
* 3
* serverId media_id
* ../12 / 58bfcfabbd501c7cd77c19bd9cfa8354.html
* 10000/
* weixin - open@qq.com,
*
* 使
*/
function uploadVoice(params: IuploadResource): void;
/**
*
*/
function downloadVoice(params: IdownloadResource): void;
/*=============================音频接口================================*/
/*=============================智能接口================================*/
interface ItranslateVoice extends BaseParams {
localId: string; // 需要识别的音频的本地Id由录音相关接口获得
isShowProgressTips: number; // 默认为1显示进度提示
success(res: { translateResult: string }): void;
}
/**
*
*/
function translateVoice(params: ItranslateVoice): void;
/*=============================智能接口================================*/
/*=============================设备信息================================*/
type networkType = "2g" | "3g" | "4g" | "wifi";
interface IgetNetworkType extends BaseParams {
success(res: { networkType: networkType }): void;
}
/**
*
*/
function getNetworkType(params: IgetNetworkType): void;
/*=============================设备信息================================*/
/*=============================地理位置================================*/
interface IopenLocation extends BaseParams {
latitude: number; // 纬度浮点数范围为90 ~ -90
longitude: number; // 经度浮点数范围为180 ~ -180。
name: string; // 位置名
address: string; // 地址详情说明
scale: number; // 地图缩放级别,整形值,范围从1~28。默认为最大
infoUrl: string; // 在查看位置界面底部显示的超链接,可点击跳转
}
/**
* 使
*/
function openLocation(params: IopenLocation): void;
interface IgetLocation extends BaseParams {
type: "wgs84" | "gcj02"; // 默认为wgs84的gps坐标如果要返回直接给openLocation用的火星坐标可传入'gcj02'
success(res: {
latitude: number; // 纬度浮点数范围为90 ~ -90
longitude: number; // 经度浮点数范围为180 ~ -180。
speed: number; // 速度,以米/每秒计
accuracy: number; // 位置精度
}): void;
}
/**
*
*/
function getLocation(params: IgetLocation): void;
/*=============================地理位置================================*/
/*=============================摇一摇周边================================*/
interface IstartSearchBeacons extends BaseParams {
ticket: string; // 摇周边的业务ticket, 系统自动添加在摇出来的页面链接后面
// 开启查找完成后的回调函数
complete(argv: any): void;
}
/**
* ibeacon设备接口
*
*/
function startSearchBeacons(params: IstartSearchBeacons): void;
interface IstopSearchBeacons extends BaseParams {
// 关闭查找完成后的回调函数
complete(res: any): void;
}
/**
* ibeacon设备接口
*/
function stopSearchBeacons(params: IstopSearchBeacons): void;
interface IonSearchBeacons extends BaseParams {
// 回调函数,可以数组形式取得该商家注册的在周边的相关设备列表
complete(argv: any): void;
}
/**
* ibeacon设备接口
*/
function onSearchBeacons(params: IonSearchBeacons): void;
/*=============================摇一摇周边================================*/
/*=============================界面操作================================*/
/**
*
*/
function hideOptionMenu(): void;
/**
*
*/
function showOptionMenu(): void;
/**
*
*/
function closeWindow(): void;
interface IhideMenuItems extends BaseParams {
menuList: Array<menuProtected | menuShare>; // 要隐藏的菜单项只能隐藏“传播类”和“保护类”按钮所有menu项见附录3
}
/**
*
*/
function hideMenuItems(params: IhideMenuItems): void;
interface IshowMenuItems extends BaseParams {
menuList: menuList; // 要显示的菜单项所有menu项见附录3
}
/**
*
*/
function showMenuItems(params: IshowMenuItems): void;
/**
*
* 3
*/
function hideAllNonBaseMenuItem(): void;
/**
*
*/
function showAllNonBaseMenuItem(): void;
/*=============================界面操作================================*/
/*=============================微信扫一扫================================*/
type scanType = "qrCode" | "barCode";
interface IscanQRCode extends BaseParams {
needResult: 0 | 1; // 默认为0扫描结果由微信处理1则直接返回扫描结果
scanType: scanType[]; // 可以指定扫二维码还是一维码,默认二者都有
// 当needResult 为 1 时,扫码返回的结果
success(res: { resultStr: string }): void;
}
/**
*
*/
function scanQRCode(params: IscanQRCode): void;
/*=============================微信扫一扫================================*/
/*=============================微信小店================================*/
interface IopenProductSpecificView extends BaseParams {
productId: string; // 商品id
viewType: "0" | "1" | "2"; // 0.默认值普通商品详情页1.扫一扫商品详情页2.小店商品详情页
}
/**
*
*/
function openProductSpecificView(params: IopenProductSpecificView): void;
/*=============================微信卡券================================*/
interface IchooseCard extends BaseParams {
shopId: string; // 门店Id
cardType: string; // 卡券类型
cardId: string; // 卡券Id
timestamp: number; // 卡券签名时间戳
nonceStr: string; // 卡券签名随机串
signType: string; // 签名方式,默认'SHA1'
cardSign: string; // 卡券签名
success(res: { cardList: string[] }): void;
}
/**
*
*/
function chooseCard(params: IchooseCard): void;
interface IaddCard extends BaseParams {
cardList: Array<{
cardId: string;
cardExt: string;
}>; // 需要添加的卡券列表
success(res: { cardList: string[] }): void;
}
/**
*
*/
function addCard(): void;
interface IopenCard extends BaseParams {
cardList: Array<{
cardId: string;
code: string;
}>; // 需要打开的卡券列表
}
/**
*
*/
function openCard(params: IopenCard): void;
interface IconsumeAndShareCard extends BaseParams {
cardId: string;
code: string;
}
/**
*
*/
function consumeAndShareCard(params: IconsumeAndShareCard): void;
/*=============================微信卡券================================*/
/*=============================微信支付================================*/
interface IchooseWXPay extends BaseParams {
timestamp: number; // 支付签名时间戳注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
nonceStr: string; // 支付签名随机串,不长于 32 位
package: string; // 统一支付接口返回的prepay_id参数值提交格式如prepay_id=***
signType: string; // 签名方式,默认为'SHA1',使用新版支付需传入'MD5'
paySign: string; // 支付签名
// 支付成功后的回调函数
success(res: any): void;
}
/**
*
*/
function chooseWXPay(params: IchooseWXPay): void;
/*=============================微信支付================================*/
/*=============================微信小程序==============================*/
interface miniProgramMethodsParams extends BaseParams {
url: string;
}
interface miniProgramMethods {
navigateTo(params: miniProgramMethodsParams): void;
navigateBack(params: miniProgramMethodsParams): void;
switchTab(params: miniProgramMethodsParams): void;
reLaunch(params: miniProgramMethodsParams): void;
redirectTo(params: miniProgramMethodsParams): void;
postMessage(params: { data: any }): void;
getEnv(fn: (res: any) => void): void;
}
const miniProgram: miniProgramMethods;
/*=============================微信小程序==============================*/
}
declare function wx(): void;
/*=============================微信内全局变量==============================*/
declare global {
interface Window {
WeixinJSBridge: any;
__wxjs_environment: any;
}
const WeixinJSBridge: any;
}
export default wx;

1346
index.js

File diff suppressed because it is too large Load Diff

File diff suppressed because one or more lines are too long

View File

@ -1,10 +1,12 @@
{ {
"name": "weixin-js-sdk", "name": "weixin-js-sdk",
"version": "1.2.0", "version": "1.6.5",
"license": "MIT",
"main": "index.js", "main": "index.js",
"description": "微信官方 js-sdk CommonJS 版", "description": "微信官方 js-sdk npm 安装版,支持 typescript",
"repository": { "repository": {
"type": "git", "type": "git",
"url": "https://github.com/yanxi-com/weixin-js-sdk.git" "url": "https://github.com/yanxi123-com/weixin-js-sdk"
} },
"homepage": "https://yanxi123.com/"
} }