首页 > 编程语言 >node服务器接入微信与企业微信js-sdk 第二篇

node服务器接入微信与企业微信js-sdk 第二篇

时间:2023-02-10 09:33:12浏览次数:68  
标签:node console log 微信 js result res wx

结合第一篇使用

home.js

import axios from "axios";
// 微信
async getStoreWXConfig() {
  try {
    const { data } = await axios.get("/apiWx/wechat-config", {
      params: {
        operate: "getJsapiConfig",
        url: window.location.href,
      },
    });
    // console.log("result", data);
    return data;
  } catch (error) {
    console.log("getStoreWXConfig", error);
    return false;
  }
}
// 企业微信
async getStoreQYWXConfig() {
  try {
    const { data } = await axios.get("/apiWx/qywechat-config", {
      params: {
        operate: "getJsapiConfig",
        url: window.location.href,
      },
    });
    // console.log("result", data);
    return data;
  } catch (error) {
    console.log("getStoreWXConfig", error);
    return false;
  }
}

main.js

import Vue from "vue";
Vue.prototype.$wx = window.wx;

调用

// 微信
async getAppWXConfig() {
  const result = await this.getStoreWXConfig();

  if (result.success) {
    // console.log("result", result);
    const { appId, timestamp, nonceStr, signature, jsApiList } =
      result.data;
    this.$wx.config({
      debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
      appId,
      timestamp: parseInt(timestamp),
      nonceStr,
      signature,
      jsApiList,
    });

    this.$wx.ready(() => {
      console.log("getAppWXConfig ready");
    });
  }
}
// 企业微信
async getAppQYWXConfig() {
  const result = await this.getStoreQYWXConfig();

  if (result.success) {
    // console.log("result", result);
    const { corpid, agentid, timestamp, nonceStr, signature, jsApiList } =
      result.data;
    this.$wx.config({
      beta: true, // 必须这么写,否则wx.invoke调用形式的jsapi会有问题
      debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
      appId: corpid,
      timestamp: parseInt(timestamp),
      nonceStr,
      signature,
      jsApiList,
    });

    this.$wx.ready(() => {
      console.log("getAppQYWXConfig ready");
    });
    this.$wx.checkJsApi({
      jsApiList, // 需要检测的JS接口列表,所有JS接口列表见附录2,
      success: function (res) {
        console.log("checkJsApi", res);
        // 以键值对的形式返回,可用的api值true,不可用为false
        // 如:{"checkResult":{"chooseImage":true},"errMsg":"checkJsApi:ok"}
      },
      fail: function (res) {
        console.log("checkJsApi fail", res);
      },
    });
    this.$wx.agentConfig({
      corpid, // 必填,企业微信的corpid,必须与当前登录的企业一致
      agentid, // 必填,企业微信的应用id
      timestamp: parseInt(timestamp), // 必填,生成签名的时间戳
      nonceStr, // 必填,生成签名的随机串
      signature, // 必填,签名,见附录1
      jsApiList, //必填
      success: function (res) {
        // 回调
        console.log("agentConfig", res);
      },
      fail: function (res) {
        console.log("agentConfig fail", res);
        if (res.errMsg.indexOf("function not exist") > -1) {
          alert("版本过低请升级");
        }
      },
    });
  }
}

作者:白马不是马

标签:node,console,log,微信,js,result,res,wx
From: https://www.cnblogs.com/DTCLOUD/p/17107825.html

相关文章

  • 花了半个小时基于 ChatGPT 搭建了一个微信机器人
    相信大家最近被ChatGPT刷屏了,其实在差不多一个月前就火过一次,不会那会好像只在程序员的圈子里面火起来了,并没有被大众认知到,不知道最近是因为什么又火起来了,而且这次搞的......
  • 关于 NodeJs 处理超长字符串问题的分析
    问题:对于超大的stringV8不能支持问题背景在Nodejs计算服务中,对端上上报的内存信息二进制数据进行预处理+缓存时,遇到了一个奇怪的报错:RangeError:Invalidstringlen......
  • 基于AST的babel库实现js反混淆还原基础案例荟萃
    基本概念AST简介AST全称AbstractSyntaxTree,即抽象语法树,简称语法树(Syntaxtree),树上的每个节点都表示源代码中的一种结构。JavaScript领域常用的AST解析库有babel、esp......
  • threejs_单例模式_项目结构_tansform控制器_css2dlabel_事件派发EventDispacher_事件
    /Users/song/Code/threejs_learn_vanilla_class_singleton/threejs_learn_vanilla_ts_class_singleton/src/main.tsimport"./style.css";importBasefrom"./threejs/......
  • js数据类型转换代码
    <!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metahttp-equiv="X-UA-Compatible"content="IE=edge"><metaname="viewport"content="width......
  • SequelizeJS 中的慢关联
    我正在尝试诊断使用SequlizeJS作为ORM的Express应用程序出现一些速度下降的原因。我有一个与其他2个模型有2xhasMany和hasOne关系的模型:更新:我已经使用cla......
  • 响应 json 的全局时间格式
    没有配置json的全局时间格式server:port:9090spring:profiles:#环境设置active:devdatasource:driver-class-name:com.mysql.cj.jdbc.Driv......
  • three.js教程7-PBR材质与环境贴图
    1、PBR材质PBR是基于物理的渲染(physically-basedrendering)。模拟物体表面的反射算法。Three.js提供了两个PBR材质相关的类MeshStandardMaterial和MeshPhysicalMateria......
  • three.js教程8-渲染器和前端UI界面
    1、html的UI交互界面与Canvas画布叠加需求:把threejsCavnas画布和HTML元素叠加布局,在canvas上添加按钮,通过按钮点击修改canvas场景。//canvas画布绝对定位renderer.do......
  • three.js教程6-加载外部三维模型gltf
    1、建模软件   3D美术常用的三维建模软件,比如Blender、3damx、C4D、maya等等Blender(轻量、免费、开源)3damxC4Dmaya   机械相关:SW、UG等   建筑......