引入
ts
import { genSignature, getWxCfg } from 't-comm';
// 不支持 tree-shaking 的项目
import { genSignature, getWxCfg} from 't-comm/lib/wx/index';
// 只支持 ESM 的项目
import { genSignature, getWxCfg} from 't-comm/es/wx/index';genSignature(ticket, url)
描述:获取jsAPI签名 校验地址:https://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign 文档地址:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html
参数:
| 参数名 | 类型 | 描述 |
|---|---|---|
| ticket | string | 票据 |
| url | string | 当前url,不包括#之后的部分 |
返回: signature
示例
ts
const sig = genSignature('jsapi_ticket_xxx', 'https://example.com/page');
// {
// timestamp: 1700000000,
// nonceStr: 'random-12-bytes-hex',
// signature: 'sha1-hex-string',
// url: 'https://example.com/page',
// }getWxCfg(apiList, openTagList)
描述:请求微信鉴权接口
参数:
| 参数名 | 类型 | 描述 |
|---|---|---|
| apiList | \* | api列表 |
| openTagList | \* | openTag列表 |
返回: Promise
微信鉴权结果