How to use wechat-jssdk - 4 common examples

To help you get started, we’ve selected a few wechat-jssdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github SolidZORO / leaa / packages / leaa-api / src / modules / oauth / oauth.service.ts View on Github external
const CLS_NAME = 'OauthService';

@Injectable()
export class OauthService {
  constructor(
    @InjectRepository(User) private readonly userRepository: Repository,
    @InjectRepository(Oauth) private readonly oauthRepository: Repository,
  ) {}

  // prettier-ignore
  // eslint-disable-next-line max-len
  private checkMiniProgramConfig = () => oauthConfig.wechat.miniProgram && oauthConfig.wechat.miniProgram.appId && oauthConfig.wechat.miniProgram.appSecret;
  private checkWechatConfig = () => oauthConfig.wechat.appId && oauthConfig.wechat.appSecret;

  private wechat = this.checkWechatConfig() && new Wechat(oauthConfig.wechat);
  private wechatOAuth = this.checkWechatConfig() && new OAuth(oauthConfig.wechat);
  private miniProgram = this.checkMiniProgramConfig() && new MiniProgram(oauthConfig.wechat);

  async bindUserIdToOauth(user: User, oid: number): Promise {
    if (!oid || typeof Number(oid) !== 'number') return errorUtil.ERROR({ error: `Nout Found oid ${oid}`, user });

    const oauth = await this.oauthRepository.findOne({ id: Number(oid) });
    if (!oauth) return errorUtil.ERROR({ error: `Not Found Oauth ${oid}`, user });

    const result = await this.oauthRepository.update(Number(oid), { user_id: user.id });
    if (!result) return errorUtil.ERROR({ error: `Binding ${oid} Failed`, user });

    return result;
  }

  async clearTicket(oauthId: number): Promise {
github SolidZORO / leaa / packages / leaa-api / src / modules / oauth / oauth.service.ts View on Github external
@Injectable()
export class OauthService {
  constructor(
    @InjectRepository(User) private readonly userRepository: Repository,
    @InjectRepository(Oauth) private readonly oauthRepository: Repository,
  ) {}

  // prettier-ignore
  // eslint-disable-next-line max-len
  private checkMiniProgramConfig = () => oauthConfig.wechat.miniProgram && oauthConfig.wechat.miniProgram.appId && oauthConfig.wechat.miniProgram.appSecret;
  private checkWechatConfig = () => oauthConfig.wechat.appId && oauthConfig.wechat.appSecret;

  private wechat = this.checkWechatConfig() && new Wechat(oauthConfig.wechat);
  private wechatOAuth = this.checkWechatConfig() && new OAuth(oauthConfig.wechat);
  private miniProgram = this.checkMiniProgramConfig() && new MiniProgram(oauthConfig.wechat);

  async bindUserIdToOauth(user: User, oid: number): Promise {
    if (!oid || typeof Number(oid) !== 'number') return errorUtil.ERROR({ error: `Nout Found oid ${oid}`, user });

    const oauth = await this.oauthRepository.findOne({ id: Number(oid) });
    if (!oauth) return errorUtil.ERROR({ error: `Not Found Oauth ${oid}`, user });

    const result = await this.oauthRepository.update(Number(oid), { user_id: user.id });
    if (!result) return errorUtil.ERROR({ error: `Binding ${oid} Failed`, user });

    return result;
  }

  async clearTicket(oauthId: number): Promise {
    await this.oauthRepository.update(oauthId, { ticket: '', ticket_at: '' });
  }
github SolidZORO / leaa / packages / leaa-api / src / modules / oauth / oauth.service.ts View on Github external
const CLS_NAME = 'OauthService';

@Injectable()
export class OauthService {
  constructor(
    @InjectRepository(User) private readonly userRepository: Repository,
    @InjectRepository(Oauth) private readonly oauthRepository: Repository,
  ) {}

  // prettier-ignore
  // eslint-disable-next-line max-len
  private checkMiniProgramConfig = () => oauthConfig.wechat.miniProgram && oauthConfig.wechat.miniProgram.appId && oauthConfig.wechat.miniProgram.appSecret;
  private checkWechatConfig = () => oauthConfig.wechat.appId && oauthConfig.wechat.appSecret;

  private wechat = this.checkWechatConfig() && new Wechat(oauthConfig.wechat);
  private wechatOAuth = this.checkWechatConfig() && new OAuth(oauthConfig.wechat);
  private miniProgram = this.checkMiniProgramConfig() && new MiniProgram(oauthConfig.wechat);

  async bindUserIdToOauth(user: User, oid: number): Promise {
    if (!oid || typeof Number(oid) !== 'number') return errorUtil.ERROR({ error: `Nout Found oid ${oid}`, user });

    const oauth = await this.oauthRepository.findOne({ id: Number(oid) });
    if (!oauth) return errorUtil.ERROR({ error: `Not Found Oauth ${oid}`, user });

    const result = await this.oauthRepository.update(Number(oid), { user_id: user.id });
    if (!result) return errorUtil.ERROR({ error: `Binding ${oid} Failed`, user });

    return result;
  }

  async clearTicket(oauthId: number): Promise {
    await this.oauthRepository.update(oauthId, { ticket: '', ticket_at: '' });
github mpcast / mpcast-server / packages / core / src / restApi / controllers / wechat / wechat.controller.ts View on Github external
constructor(
        private readonly jwtService: JwtService,
        private readonly usersService: UserService,
        private readonly cacheService: CacheService,
    ) {
        this.wx = new Wechat(this.wechatConfig);
        this.mp = this.wx.miniProgram;
    }

wechat-jssdk

WeChat JS-SDK integration with NodeJS and Web

MIT
Latest version published 1 year ago

Package Health Score

43 / 100
Full package analysis