shortlink.generate 微信小程序分享

本文主要是介绍shortlink.generate 微信小程序分享,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

【官方文档】:shortlink.generate https://developers.weixin.qq.com/miniprogram/dev/api-backend/open-api/short-link/shortlink.generate.html

需求: 在这里插入图片描述

获取小程序 Short Link 方法

@Value("${wxmini.appId:}") private String appId; @Value("${wxmini.appSecret:}") private String appSecret; /** * 微信API服务 */ private WxMaService wxMaService; @PostConstruct public void init() { WxMaDefaultConfigImpl config = new WxMaDefaultConfigImpl(); config.setAppid(appId); config.setSecret(appSecret); wxMaService = new WxMaServiceImpl(); wxMaService.setWxMaConfig(config); } /** * 获取小程序 Short Link */ public String getShortLink(String pageUrl, String pageTitle, boolean isPermanent) throws Exception { try { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("page_url", pageUrl); jsonObject.addProperty("page_title", pageTitle); jsonObject.addProperty("is_permanent", isPermanent); String res = this.wxMaService.post("https://api.weixin.qq.com/wxa/genwxashortlink", jsonObject.toString()); if (StringUtils.isBlank(res)) { throw new Exception("获取小程序 Short Link异常"); } JSONObject obj = JSONObject.parseObject(res); return obj.getString("link"); } catch (Exception e) { log.error("获取小程序 Short Link异常,msg=" + e.getMessage(), e); throw new Exception("获取小程序 Short Link异常"); } }

配置: 版本比较老,自行升级

1.8 3.9.6.B com.github.binarywang weixin-java-open ${binarywang.version}

# 微信小程序 配置wxmini.appId=wxmini.appSecret=

踩过的坑:

"errcode":40066,"errmsg":"invalid url"

在这里插入图片描述 url 需要是发布的小程序有的 url 。 不是指的请求 url “https://api.weixin.qq.com/wxa/genwxashortlink”, 而是参数 “page_url”

https://developers.weixin.qq.com/community/develop/doc/000c685e7b4968c7a08d92a8a51c00?highLine=shortlink.generate

这篇关于shortlink.generate 微信小程序分享的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持

文章版权声明:除非注明,否则均为 谢士广博客 原创文章,转载或复制请以超链接形式并注明出处。

发表评论

快捷回复: 表情:
AddoilApplauseBadlaughBombCoffeeFabulousFacepalmFecesFrownHeyhaInsidiousKeepFightingNoProbPigHeadShockedSinistersmileSlapSocialSweatTolaughWatermelonWittyWowYeahYellowdog
评论列表 (暂无评论,454人围观)

还没有评论,来说两句吧...

目录[+]