page_url:"pages/games/home/home?activityId=197&platformId=0&tenantId=1&type=1"
page_title:""
is_permanent:false
获取短链接成功,但获取到的短链接一直跳转到小程序首页。未按预期跳转到设定的path。
JAVA代码如下:
@Data
@ApiModel
public class WeixinMiniShortLinkReq extends CmsBaseReq {
/**
*
*/
private static final long serialVersionUID = 1L;
@ApiModelProperty(value = "通过 Short Link 进入的小程序页面路径,必须是已经发布的小程序存在的页面,可携带 query,最大1024个字符", required = true)
private String pageUrl;
@ApiModelProperty(value = "页面标题,不能包含违法信息,超过20字符会用... 截断代替")
private String pageTitle;
@ApiModelProperty(value = "默认值false。短期有效:false,永久有效:true", required = true)
private Boolean isPermanent;
}
/**
* 获取ShortLink
*/
private static final String GET_SHORT_LINK = "https://api.weixin.qq.com/wxa/genwxashortlink?access_token={0}";
@Override
public CommonResult<WeixinMiniGetShortLinkResultVO> getShortLink(WeixinMiniShortLinkReq req) {
//获取接口调用凭证
String accessToken = wxUtil.getAccessToken();
if (StringUtils.isEmpty(accessToken)) {
return CommonResult.failed("接口调用凭证获取失败");
}
String url = MessageFormat.format(GET_SHORT_LINK, accessToken);
JSONObject params = new JSONObject();
params.put("page_url", req.getPageUrl());
params.put("page_title", req.getPageTitle());
params.put("is_permanent", req.getIsPermanent());
String bodyParam = params.toJSONString();
try {
String resultStr = httpAPIUtil.doPost(url, bodyParam);
log.info("url={}\n body={}\n result={}", url, bodyParam, resultStr);
WeixinMiniGetShortLinkResultVO resultVO = JSONObject.parseObject(resultStr, WeixinMiniGetShortLinkResultVO.class);
return CommonResult.success(resultVO);
} catch (Exception e) {
log.info("url={}\n body={}\n Exception={}", url, bodyParam, e.getMessage());
log.error("获取小程序 Short Link失败", e);
return CommonResult.failed("获取小程序 Short Link失败");
}
}
ShortLink 提供下呢?