import * as util from 'util' ; import { AccessToken , AccessTokenApi } from '@tnwx/accesstoken' ; import { HttpKit } from '@tnwx/kits' ; author Javen
 *  copyright description export class ComSubscribeMsgApi { private static addTemplateUrl : string = 'https://api.weixin.qq.com/wxaapi/newtmpl/addtemplate?access_token=%s' ; private static delTemplateUrl : string = 'https://api.weixin.qq.com/wxaapi/newtmpl/deltemplate?access_token=%s' ; private static getCategoryUrl : string = 'https://api.weixin.qq.com/wxaapi/newtmpl/getcategory?access_token=%s' ; private static getPubTemplateKeyWordsUrl : string = 'https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatekeywords?access_token=%s&tid=%s' ; private static getPubTemplateTitlesUrl : string = 'https://api.weixin.qq.com/wxaapi/newtmpl/getpubtemplatetitles?access_token=%s&ids=%s&start=%s&limit=%s' ; private static getTemplateUrl : string = 'https://api.weixin.qq.com/wxaapi/newtmpl/gettemplate?access_token=%s' ; private static sendMessageUrl : string = 'https://api.weixin.qq.com/cgi-bin/message/subscribe/bizsend?access_token=%s' ; param tid param kidList param sceneDesc public static async addTemplate ( tid , kidList , sceneDesc ? ) { let accessToken = await AccessTokenApi . getAccessToken ( ) ; let url = util . format ( this . addTemplateUrl , ( < AccessToken > accessToken ) . getAccessToken ) ; return HttpKit . getHttpDelegate . httpPost ( url , JSON . stringify ( { tid : tid , kidList : kidList , sceneDesc : sceneDesc } ) ) ; } param priTmplId public static async delTemplate ( priTmplId ) { let accessToken = await AccessTokenApi . getAccessToken ( ) ; let url = util . format ( this . delTemplateUrl , ( < AccessToken > accessToken ) . getAccessToken ) ; return HttpKit . getHttpDelegate . httpPost ( url , JSON . stringify ( { priTmplId : priTmplId } ) ) ; } /**
     * 获取公众号类目
     */ public static async getCategory ( ) { let accessToken = await AccessTokenApi . getAccessToken ( ) ; let url = util . format ( this . getCategoryUrl , ( < AccessToken > accessToken ) . getAccessToken ) ; return HttpKit . getHttpDelegate . httpGet ( url ) ; } param tid public static async getPubTemplateKeyWords ( tid ) { let accessToken = await AccessTokenApi . getAccessToken ( ) ; let url = util . format ( this . getPubTemplateKeyWordsUrl , ( < AccessToken > accessToken ) . getAccessToken , tid ) ; return HttpKit . getHttpDelegate . httpGet ( url ) ; } param ids param start param limit public static async getPubTemplateTitles ( ids , start = 0 , limit = 30 ) { let accessToken = await AccessTokenApi . getAccessToken ( ) ; let url = util . format ( this . getPubTemplateTitlesUrl , ( < AccessToken > accessToken ) . getAccessToken , ids . join ( ',' ) , start , limit ) ; return HttpKit . getHttpDelegate . httpGet ( url ) ; } /**
     * 获取私有模板列表
     */ public static async getTemplate ( ) { let accessToken = await AccessTokenApi . getAccessToken ( ) ; let url = util . format ( this . getTemplateUrl , ( < AccessToken > accessToken ) . getAccessToken ) ; return HttpKit . getHttpDelegate . httpGet ( url ) ; } param touser param templateId param data param page param miniprogram public static async sendSubMessage ( touser , templateId , data , page ? , miniprogram ? ) { let accessToken = await AccessTokenApi . getAccessToken ( ) ; let url = util . format ( this . sendMessageUrl , ( < AccessToken > accessToken ) . getAccessToken ) ; return HttpKit . getHttpDelegate . httpPost ( url , JSON . stringify ( { touser : touser , template_id : templateId , page : page , data : data , miniprogram : miniprogram } ) ) ; } }