微信小程序获取某页面的短连接

Controller 层
/**
invitationId 局id,具体参数可以根据业务替换,这里生成的是局详情小程序码,所以需要传入局id
 * 显示小程序对应的短连接
 */
@RequestMapping("getUrlScamel")
@ResponseBody
public Object getUrlScamel(HttpServletRequest request, Integer invitationId) {
    return wxService.getUrlScamel(invitationId);
}

Service 实现层:

@Override
public Object getUrlScamel(Integer invitationId) {
    //接口请求地址,ACCESS_TOKEN需要替换为小程序的access_token
    String postUrl = "https://api.weixin.qq.com/wxa/generatescheme?access_token=ACCESS_TOKEN";
    // String appletAccsstoken = getAppletAccsstoken();
    postUrl = postUrl.replace("ACCESS_TOKEN", getAppletAccsstoken());
   //准备请求参数
    Map<String, Object> param = new HashMap<>();
    JumpWxaVO jumpWxaVO = new JumpWxaVO();
    jumpWxaVO.setPath("pages/group-detail/group-detail");    //局详情页,必须在线上存在的页面,不可添加参数
    jumpWxaVO.setQuery("invitationId=" + invitationId);  //设置参数
    param.put("jump_wxa", jumpWxaVO);
    param.put("is_expire", true); //设置是否会过期,不设置可以改为false
    long l = System.currentTimeMillis() / 1000;
    param.put("expire_time", l + 3600L * 24 * 30); //设置过期时间,过期时间为true必传
    String post = HttpUtil.post(postUrl, JSONObject.toJSONString(param));  //hutool工具类 发送请求
   //解析数据    
  JSONObject jsonObject = JSONObject.parseObject(post); 
    String openlink = jsonObject.get("openlink").toString();   //获取小程序短连接
   //todo 获取短连接之后自己保存好数据 
   return openlink;
JumpWxaVO实体类:
@Data
public class JumpWxaVO {
    /**
     * 小程序跳转路径
     */
    private String path;
    /**
     * 查询参数
     */
    private String query;
}

hutool引用:

<dependency>
    <groupId>cn.hutool</groupId>
    <artifactId>hutool-all</artifactId>
    <version>5.2.5</version>
</dependency>

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值