import { HttpException , HttpService , Inject , Injectable } from '@nestjs/common' ; import { WeChatUtil } from '../../utile/wechat.util' ; @ Injectable ( ) export class WechatUser { constructor ( @ Inject ( WeChatUtil ) private readonly wechatUtil , @ Inject ( HttpService ) private readonly httpService ) { } param { string } appid param parameter returns { Promise < { code : number ; message : string ; data : any } > } async queryUserInformation ( appid , parameter ) { if ( ! appid ) { throw new HttpException ( 'appid不存在！！' , 500 ) ; } const accessToken = await this . wechatUtil . ensureAccessToken ( appid ) ; const url = `https://api.weixin.qq.com/cgi-bin/user/info/batchget?access_token=${ accessToken }` ; const { data } = await this . httpService . post ( url , parameter ) . toPromise ( ) ; if ( data . errcode ) { throw new HttpException ( data . errmsg , data . errcode ) ; } return { code : 200 , message : '获取用户基本信息成功!' , data } ; } param { string } appid param parameter returns { Promise < { code : number ; message : string ; data : any } > } async queryUserList ( appid , parameter ) { if ( ! appid ) { throw new HttpException ( 'appid不存在！！' , 500 ) ; } const accessToken = await this . wechatUtil . ensureAccessToken ( appid ) ; const url = `https://api.weixin.qq.com/cgi-bin/user/get?access_token=${ accessToken }&next_openid=${ parameter . nextOpenId }` ; const { data } = await this . httpService . get ( url ) . toPromise ( ) ; if ( data . errcode ) { throw new HttpException ( data . errmsg , data . errcode ) ; } return { code : 200 , message : '获取关注用户列表成功!' , data } ; } }