/// /// import { Request, Response } from 'express'; import { AccountAccessTokenResult, AccountCreateQRCode, AccountCreateQRCodeResult, DefaultRequestResult, SignatureResult, TemplateMessage, TicketResult, UserAccessTokenResult, UserInfoResult, WeChatModuleOptions } from '.'; import { MiniProgramService } from './miniprogram.service'; import { ICache } from './types/utils'; import { WePayService } from './wepay.service'; export declare class WeChatService { private options; private readonly logger; /** * key_access_token * @static * @memberof WeChatService */ static KEY_ACCESS_TOKEN: string; /** * key_ticket * @static * @memberof WeChatService */ static KEY_TICKET: string; protected _cacheAdapter: ICache; /** * MiniProgram Service Namespace * * @type {MiniProgramService} * @memberof WeChatService */ mp: MiniProgramService; /** * WePay Service Namespace * @type {WePayService} * @memberof WeChatService */ pay: WePayService; private debug; set cacheAdapter(adapter: ICache); get cacheAdapter(): ICache; constructor(options: WeChatModuleOptions); /** * * @deprecated * @memberof WeChatService */ get config(): WeChatModuleOptions; /** * @deprecated * @memberof WeChatService */ set config(options: WeChatModuleOptions); /** * * 获取公众号或者小程序Access token * * 正确返回 * * {"access_token": "52_s0Mcl3E3DBKs12rthjxG8_DOvsIC4puV9A34WQR6Bhb_30TW9W9BjhUxDRkyph-hY9Ab2QS03Q8wZBe5UkA1k0q0hc17eUDZ7vAWItl4iahnhq_57dCoKc1dQ3AfiHUKGCCMJ2NcQ0BmbBRIKBEgAAAPGJ", "expires_in": 7200} * * 错误返回 * {"errcode":40013,"errmsg":"invalid appid"} * * @param _appId * @param _secret * @tutorial https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html * @returns */ getAccountAccessToken(_appId?: string, _secret?: string): Promise; /** * * # 获取稳定版接口调用凭据 * * ## 功能描述 * * + 获取公众号全局后台接口调用凭据,有效期最长为7200s,开发者需要进行妥善保存; * + 有两种调用模式: 1. 普通模式,access_token 有效期内重复调用该接口不会更新 access_token,绝大部分场景下使用该模式;2. 强制刷新模式,会导致上次获取的 access_token 失效,并返回新的 access_token; * + 该接口调用频率限制为 1万次 每分钟,每天限制调用 50w 次; * + 与获取Access token获取的调用凭证完全隔离,互不影响。该接口仅支持 POST JSON 形式的调用; * * ## 使用调试工具构造请求 * * [微信公众平台接口调试工具](https://mp.weixin.qq.com/debug/) * * body * * ```json * { * "grant_type": "client_credential", * "appid": "your/appid", * "secret": "your/secret", * "force_refresh": false * } * ``` * * @param _appId * @param _secret * @tutorial https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/getStableAccessToken.html * @returns */ getStableAccessToken(_appId?: string, _secret?: string, force?: boolean): Promise; /** * 读取access token的逻辑封装 * * @param _appId * @param _secret * @returns */ private getToken; /** * * 读取JS-SDK Ticket逻辑封装 * * @param _appId * @param _secret * @returns */ private getTicket; /** * * 获取jsapi_ticket * * 成功返回 * {"errcode":0, "errmsg":"ok", "ticket":"bxLdikRXVbTPdHSM05e5u5sUoXNKd8-41ZO3MhKoyN5OfkWITDGgnr2fwJ0m9E8NYzWKVZvdVtaUgWvsdshFKA", "expires_in":7200} * 错误返回 * * @tutorial https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#62 * @param _appId * @param _secret * @returns */ getJSApiTicket(_appId?: string, _secret?: string): Promise; /** * * 对URL进行权限签名 * sign a url * * @param {String} url url for signature * @throws {Error} * @link https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#62 */ jssdkSignature(url: string): Promise; /** * * 对URL进行权限签名 * sign a url * * @param {String} url * @param {String} appId * @param {String} secret * @throws {Error} * @link https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html#62 */ jssdkSignature(url: string, appId: string, secret: string): Promise; /** * 微信消息推送处理函数,基于express, * * 函数返回解密后的文本。 * * 使用方法参考tests/wechat.controller.ts * * @param req express Request对象 * @param res express Response对象,提供res参数会自动调用res.send() * @param resText 调用res.send()时的回复内容,不提供则回复空串 * @returns */ messagePushExpressHandler(req: Request, res?: Response, resText?: string): Promise; /** * 明文模式微信消息推送处理函数,基于express * * 函数返回微信推送文本内容 * * 使用方法参考tests/wechat.controller.ts * * @param req express Request对象 * @param res express Response对象,提供res参数会自动调用res.send() * @param resText 调用res.send()时的回复内容,不提供则回复空串 * @returns */ plainMessagePushExpressHandler(req: Request, res?: Response, resText?: string): Promise; /** * 微信公众号基本配置的服务器配置验证接口封装,基于express。 * * 使用方法参考tests/wechat.controller.ts * * @param req * @param res */ checkSignatureExpress(req: Request, res: Response, token?: string): void; /** * * Check token saved in the cache * * @param token * @returns */ private checkAccessToken; /** * * Check ticket saved in the cache * * @param ticket * @returns */ private checkTicket; private chooseAppIdAndSecret; /** * * 通过code换取网页授权access_token * * 正确返回 * * { * * "access_token":"ACCESS_TOKEN", * * "expires_in":7200, * * "refresh_token":"REFRESH_TOKEN", * * "openid":"OPENID", * * "scope":"SCOPE" * * } * * 错误返回 * * {"errcode":40029,"errmsg":"invalid code"} * * {"errcode":40013,"errmsg":"iinvalid appid, rid: 61c82e61-2e62fb72-467cb9ec"} * * @param {String} code * @param {String} appId * @param {String} secret * @returns * @tutorial https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html#1 */ getAccessTokenByCode(code: string, _appId?: string, _secret?: string): Promise; /** * 拉取用户信息(需scope为 snsapi_userinfo) * * 如果网页授权作用域为snsapi_userinfo,则此时开发者可以通过access_token和openid拉取用户信息了。 * * @param accessToken 通过code换取网页授权access_token * @param openid 用户的唯一标识 * @param lang 返回国家地区语言版本,zh_CN 简体,zh_TW 繁体,en 英语,默认zh_CN * @returns * @tutorial https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/Wechat_webpage_authorization.html#3 */ getUserInfo(accessToken: string, openid: string, lang?: 'zh_CN' | 'zh_TW' | 'en'): Promise; /** * * 公众号向用户发送模板消息 * * @param message * @returns * @tutorial https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html#5 */ sendTemplateMessage(message: TemplateMessage, appId?: string, secret?: string): Promise; /** * 生成带参数的二维码 * @param data * @param appId * @param secret * @returns * @tutorial https://developers.weixin.qq.com/doc/offiaccount/Account_Management/Generating_a_Parametric_QR_Code.html */ createQRCode(data: AccountCreateQRCode, appId?: string, secret?: string): Promise; /** * 通过ticket换取二维码 * * 参数TICKET记得进行UrlEncode * * @param ticket 需要UrlEncode * @returns */ showQRCode(ticket: string): Promise>; /** * * 消息加密 * * @param message 明文消息 * @param timestamp 时间戳 * @param nonce 随机字符串 * @returns XML格式字符串 * @link https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/Technical_Plan.html * @link https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/Message_encryption_and_decryption.html */ encryptMessage(message: string, timestamp: string, nonce: string): string; /** * * 消息解密 * * @param signature 签名 * @param timestamp 时间戳 * @param nonce 随机字符串 * @param encryptXml 加密消息XML字符串 * @returns 消息明文内容 * @see WeChatService#encryptMessage * @link https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/Technical_Plan.html * @link https://developers.weixin.qq.com/doc/oplatform/Third-party_Platforms/2.0/api/Before_Develop/Message_encryption_and_decryption.html * */ decryptMessage(signature: string, timestamp: string, nonce: string, encryptXml: string): string; }