惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Simon Willison's Weblog
Simon Willison's Weblog
G
Google Developers Blog
Spread Privacy
Spread Privacy
I
InfoQ
V
V2EX
S
Schneier on Security
小众软件
小众软件
C
CERT Recently Published Vulnerability Notes
博客园 - 聂微东
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
L
Lohrmann on Cybersecurity
Recent Announcements
Recent Announcements
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
Attack and Defense Labs
Attack and Defense Labs
云风的 BLOG
云风的 BLOG
The Hacker News
The Hacker News
S
SegmentFault 最新的问题
C
Cybersecurity and Infrastructure Security Agency CISA
NISL@THU
NISL@THU
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
GbyAI
GbyAI
Latest news
Latest news
S
Secure Thoughts
Project Zero
Project Zero
MongoDB | Blog
MongoDB | Blog
I
Intezer
Security Latest
Security Latest
Apple Machine Learning Research
Apple Machine Learning Research
Vercel News
Vercel News
N
Netflix TechBlog - Medium
V2EX - 技术
V2EX - 技术
量子位
T
Threatpost
T
The Blog of Author Tim Ferriss
Y
Y Combinator Blog
T
Tor Project blog
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
T
The Exploit Database - CXSecurity.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
C
Check Point Blog
博客园 - Franky
Google DeepMind News
Google DeepMind News
The Register - Security
The Register - Security
The GitHub Blog
The GitHub Blog
L
LINUX DO - 热门话题

博客园 - 大山008

若依导出excel时decimal数据千分位格式化 SpringBoot如何引入deepseek-多轮对话 EasyExcel实现百万级数据导入导出 SpringAMQP整合RabbitMQ使用 win11安装redis步骤详解 ftp与sftp工具类 stream流的一些常用用法 子类的toString方法如何打印父类的属性 MySQL常见的几种优化方案 关于若依AsyncFactory的一些思考,记录一下 Vue 路由跳转、路由传参、跳转区别、传值取值 MYSQL中substring_index()用法 mybatis sql 解决 in 参数过多的问题 MySQL之json数据操作 mybatis查询返回map键值对的问题 validate校验,记录一种思路 在vue中用multipart/form-data方式上传文件并同表单同步提交数据 生成带有二维码的海报 java将指定文件夹下面的所有图片压缩到指定大小以内并保存图片 Lock与ReentrantLock、Synchronized
Java微信转发及网络检测
大山008 · 2023-02-03 · via 博客园 - 大山008

1、jar包引入

<dependency>
         <groupId>com.github.binarywang</groupId>
         <artifactId>weixin-java-mp</artifactId>
         <version>4.2.0</version>
 </dependency>
<!--微信支付-->
 <dependency>
         <groupId>com.github.binarywang</groupId>
         <artifactId>weixin-java-pay</artifactId>
         <version>4.2.0</version>
</dependency>

2、yml文件配置(参数可查微信开发者文档)

wx:
  pay:
    #公众号微信支付
    appId: **********
    mchId: *****
    mchKey: ****
    subAppId:
    subMchId:
    keyPath: classpath:apiclient_cert.p12
    spbillCreateIp: 39.105.71.11
  mp:
    #公众号
    appId: ****8
    secret: *****
    token:
    aesKey:

3、实现转发分享功能

参考文档:https://developers.weixin.qq.com/doc/offiaccount/OA_Web_Apps/JS-SDK.html

注意JSSDK接口不是随便就能调用的,在页面初始化阶段,需要注入接口权限验证,上一篇我们其实已经实现了,即如下方法

//返回初始化参数    
@PostMapping("/getJsApiTicket")
    public AjaxResult getJsApiTicket(String url) {
        log.debug("getJsonApi url:{}", url);
        try {
            WxJsapiSignature jsapiSignature = wxMpService.createJsapiSignature(url);
            Map map = new HashMap(2);
            map.put("js", jsapiSignature);
            log.info("js=============" + jsapiSignature);
            return AjaxResult.success(map);
        } catch (WxErrorException e) {
            log.error("获取网络状态参数错误:{}", e.getMessage());
            return AjaxResult.error();
        }
    }

页面初始化

wx.config({
    debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
    appId: result.data.js.appId, // 必填,公众号的唯一标识
    timestamp: result.data.js.timestamp, // 必填,生成签名的时间戳
    nonceStr: result.data.js.nonceStr, // 必填,生成签名的随机串
    signature: result.data.js.signature,// 必填,签名
    jsApiList: ['updateAppMessageShareData', 'updateTimelineShareData','getNetworkType'] // 必填,需要使用的JS接口列表
});

分享朋友或者qq及网络检测

wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
  wx.updateAppMessageShareData({ 
    title: '', // 分享标题
    desc: '', // 分享描述
    link: '', // 分享链接,该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
    imgUrl: '', // 分享图标
    success: function () {
      // 设置成功
    }
  })
});

分享朋友圈及qq空间

wx.ready(function () {      //需在用户可能点击分享按钮前就先调用
  wx.updateTimelineShareData({ 
    title: '', // 分享标题
    link: '', // 分享链接,该链接域名或路径必须与当前页面对应的公众号 JS 安全域名一致
    imgUrl: '', // 分享图标
    success: function () {
      // 设置成功
    }
  })
});

网络检测

网络检测
wx.getNetworkType({
    success: function (res) {
        
    }
})