开启左侧

uni-app开发企微H5——推音讯给客户(安装包版)

[复制链接]
在线会员 UK8Uf 发表于 2022-12-30 15:19:20 | 显示全部楼层 |阅读模式 打印 上一主题 下一主题
上一篇的企微拉收消息尝试了以后,发明苹因脚机不可,而后又要么尾从头瞅文档,搜处置计划。那个时候瞅到共事的一个企微客服的尝试小名目,没有瞅没有明白,一瞅吓一跳。那没有即是尔甘甘寻找的工具么?并且是颠末尝试的可用计划,奶思~
@wecom/jssdk - npm微疑(企业微疑)JSSDK,可用于替换 jweixin.js。. Latest version: 1.2.1, last published: 2 months ago. Start using @wecom/jssdk in your project by running `npm i @wecom/jssdk`. There are no other projects in the npm registry using @wecom/jssdk.
uni-app开辟企微H5——拉消息给客户(装置包版)-1.png

https://www.npmjs.com/package/@wecom/jssdk一、装置
npm i @wecom/jssdk
二、使用
假设只需一个页里需要使用到,便间接写正在页里里,以下:
  1. <template>
  2.         <view class="content">
  3.                 <image class="logo" src="/static/logo.png"></image>
  4.                 <view class="text-area">
  5.                         <text class="title">{{title}}</text>
  6.                         <view>{{ version }}</view>
  7.                         <view>{{ content }}</view>
  8.                        
  9.                 </view>
  10.         </view>
  11. </template>
  12. <script>
  13.         import * as ww from '@wecom/jssdk'
  14.         export default {
  15.                 data() {
  16.                         return {
  17.                                 title: 'Hello',
  18.                                 version: "",
  19.                                 content: ""
  20.                         }
  21.                 },
  22.                 onLoad() {
  23.                         this.version = ww.VERSION
  24.                         let _this = this
  25.                        
  26.                         ww.register({
  27.                                 corpId: "请挖进您的corpId",
  28.                                 agentId: 请挖进您的agentId,
  29.                                 jsApiList: [
  30.                                         'checkJsApi',
  31.                                         'getContext',
  32.                                         'selectExternalContact',
  33.                                         'getCurExternalContact',
  34.                                         'getCurExternalChat',
  35.                                         'sendChatMessage',
  36.                                         'launchMiniprogram'
  37.                                 ],
  38.                                 async getConfigSignature(url) {
  39.                                         let [error, res] = await uni.request({
  40.                                                 url: '挪用的交心url,js_sdkInit',
  41.                                                 data: {
  42.                                                         agentid: 请挖进您的agentId,
  43.                                                         purl: url
  44.                                                 },
  45.                                         })
  46.                                         return {
  47.                                                 timestamp: res.data.timestamp,
  48.                                                 nonceStr: res.data.nonceStr,
  49.                                                 signature: res.data.signature
  50.                                         }
  51.                                 },
  52.                                 async getAgentConfigSignature(url) {
  53.                                         let [error, res] = await uni.request({
  54.                                                 url: '挪用的交心url,Agentjs_sdkInit',
  55.                                                 data: {
  56.                                                         agentid: 1000060,
  57.                                                         purl: url
  58.                                                 },
  59.                                         })
  60.                                         console.log("getAgentConfigSignature:res",res)
  61.                                         return {
  62.                                                 timestamp: res.data.d.timestamp,
  63.                                                 nonceStr: res.data.d.nonceStr,
  64.                                                 signature: res.data.d.signature
  65.                                         }
  66.                                 },
  67.                                 onConfigSuccess(res) {
  68.                                         console.log("onConfigSuccess")
  69.                                         console.log(res)
  70.                                 },
  71.                                 onConfigFail(res) {
  72.                                         console.log("onConfigFail")
  73.                                         console.log(res)
  74.                                 },
  75.                                 onAgentConfigSuccess(res) {
  76.                                         console.log("onAgentConfigSuccess")
  77.                                         console.log(res)
  78.                                 },
  79.                                 onAgentConfigFail(res) {
  80.                                         console.log("onAgentConfigFail")
  81.                                         console.log(res)
  82.                                 }
  83.                         })
  84.                        
  85.                         //间接使用
  86.                         ww.getCurExternalContact({
  87.                                 success(res) {
  88.                                         _this.content = JSON.stringify(res)
  89.                                 }
  90.                         })
  91.                        
  92.                 },
  93.                 methods: {
  94.                 }
  95.         }
  96. </script>
  97. <style>
  98.         .content {
  99.                 display: flex;
  100.                 flex-direction: column;
  101.                 align-items: center;
  102.                 justify-content: center;
  103.         }
  104.         .logo {
  105.                 height: 200rpx;
  106.                 width: 200rpx;
  107.                 margin-top: 200rpx;
  108.                 margin-left: auto;
  109.                 margin-right: auto;
  110.                 margin-bottom: 50rpx;
  111.         }
  112.         .text-area {
  113.                 display: flex;
  114.                 justify-content: center;
  115.         }
  116.         .title {
  117.                 font-size: 36rpx;
  118.                 color: #8f8f94;
  119.         }
  120. </style>
复造代码
(1)、假设是多处使用,便写正在js里,而后正在main.js里注进。
  1. //qy_Config.js
  2. import * as ww from '@wecom/jssdk'
  3. ww.register({
  4.         corpId: "自己挖",
  5.         agentId:自己 挖,
  6.         jsApiList: [
  7.                 'checkJsApi',
  8.                 'getContext',
  9.                 'selectExternalContact',
  10.                 'getCurExternalContact',
  11.                 'getCurExternalChat',
  12.                 'sendChatMessage',
  13.                 'launchMiniprogram'
  14.         ],
  15.         async getConfigSignature(url) {
  16.                 let [error, res] = await uni.request({
  17.                         url: '自己挖',
  18.                         data: {
  19.                                 agentid:自己 挖,
  20.                                 purl: url
  21.                         },
  22.                 })
  23.                 return {
  24.                         timestamp: res.data.timestamp,
  25.                         nonceStr: res.data.nonceStr,
  26.                         signature: res.data.signature
  27.                 }
  28.         },
  29.         async getAgentConfigSignature(url) {
  30.                 let [error, res] = await uni.request({
  31.                         url: '自己挖',
  32.                         data: {
  33.                                 agentid:自己 挖,
  34.                                 purl: url
  35.                         },
  36.                 })
  37.                 console.log("getAgentConfigSignature:res", res)
  38.                 return {
  39.                         timestamp: res.data.d.timestamp,
  40.                         nonceStr: res.data.d.nonceStr,
  41.                         signature: res.data.d.signature
  42.                 }
  43.         },
  44.         onConfigSuccess(res) {
  45.                 console.log("onConfigSuccess")
  46.                 console.log(res)
  47.         },
  48.         onConfigFail(res) {
  49.                 console.log("onConfigFail")
  50.                 console.log(res)
  51.         },
  52.         onAgentConfigSuccess(res) {
  53.                 console.log("onAgentConfigSuccess")
  54.                 console.log(res)
  55.         },
  56.         onAgentConfigFail(res) {
  57.                 console.log("onAgentConfigFail")
  58.                 console.log(res)
  59.         }
  60. })
复造代码
(2)、正在main.js里注进
  1. //main.js
  2. import qy_Config from '@/co妹妹on/qy_Config.js'  //引用
复造代码
(3)、正在页里中使用,完毕拉收功用。
  1. <template>
  2.         <view>       
  3.                 <u-button class="send-btn" iconColor="#fff" @click="pushText()" type="error" shape="circle" size='mini'>尔要拉收</u-button>
  4.         </view>
  5. </template>
  6. <script>
  7.         import * as ww from '@wecom/jssdk'
  8.        
  9.         export default {
  10.                 data() {
  11.                         return {
  12.                                 content:'尔要拉收的案牍'
  13.                         };
  14.                 },
  15.                 methods:{
  16.                         // 拉收消息
  17.                         pushText(){
  18.                        
  19.                                 var that = this
  20.                                 var ua = window.navigator.userAgent.toLowerCase();
  21.                                 console.log(ua)
  22.                                 console.log(ua.match(/wxwork/i) == 'wxwork')
  23.                                 if (ua.match(/wxwork/i) == 'wxwork') {
  24.                                        
  25.                                         ww.invoke('sendChatMessage', {
  26.                                                 msgtype:"text", //消息范例,必挖
  27.                                                 enterChat: true, //为true时暗示收收完毕以后特别加入会话,仅挪动端3.1.10及以上版原撑持该字段
  28.                                                 text: {
  29.                                                         content: that.content, //文原实质
  30.                                                 }
  31.                                         }, function(res) {
  32.                                                
  33.                                                 if(res.res.err_msg == "sendChatMessage:fail_nosupport"){
  34.                                                         uni.showModal({
  35.                                                                 title: "没法拉收",
  36.                                                                 content: "目前进口没法拉收,请正在对于话栏翻开此页里操纵!"
  37.                                                         })
  38.                                                 }
  39.                                                 if (res.err_msg == 'sendChatMessage:ok') {
  40.                                                         //收收胜利
  41.                                                 }
  42.                                         })
  43.                                 } else {
  44.                                         uni.showToast({
  45.                                                 title: "请正在企业微疑端操纵",
  46.                                                 icon: "none"
  47.                                         })
  48.                                         return
  49.                                 }
  50.                                
  51.                         }
  52.                        
  53.                        
  54.                 }
  55.         }
  56. </script>
复造代码
uni-app开辟企微H5——拉收消息给客户_Strawberry96的专客-CSDN专客正在企微拉收个消息给客户如何便这样易这???别觉得有了开辟文档您就能够一往无前了!前面的路借需要您披荆棘这~
uni-app开发企微H5——推音讯给客户(安装包版)

https://blog.csdn.net/zhangying1996/article/details/123053312
您需要登录后才可以回帖 登录 | 立即注册 qq_login

本版积分规则

发布主题
阅读排行更多+
用专业创造成效
400-778-7781
周一至周五 9:00-18:00
意见反馈:server@mailiao.group
紧急联系:181-67184787
ftqrcode

扫一扫关注我们

Powered by 职贝云数A新零售门户 X3.5© 2004-2025 职贝云数 Inc.( 蜀ICP备2024104722号 )