com.tmsps.ne4weixin.api.ShortUrlAPI Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of ne4weixin Show documentation
Show all versions of ne4weixin Show documentation
Ne4WeiXin For Spring is good :)
package com.tmsps.ne4weixin.api;
import com.alibaba.fastjson.JSONObject;
import com.tmsps.ne4weixin.bean.qrcode.ShortUrl;
import com.tmsps.ne4weixin.config.WxConfig;
import com.tmsps.ne4weixin.config.constant.QRCODE;
import com.tmsps.ne4weixin.utils.WXHttpUtil;
import lombok.extern.slf4j.Slf4j;
/**
* @Title: ShortUrlAPI.java
* @Package: com.tmsps.ne4weixin.api
* @Description: 长链接转短链接API
* @author: hanjiefei
* @date: 2019-10-22
* @version V1.0
* @Copyright: 2019
*/
@Slf4j
public class ShortUrlAPI extends BaseAPI {
private String accessToken = null;
public ShortUrlAPI(String accessToken) {
super(null);
this.accessToken = accessToken;
}
public ShortUrlAPI(WxConfig config) {
super(config);
this.accessToken = config.getAccessToken();
}
/**
* 长链接转短链接
* @param longUrl
* @return
*/
public ShortUrl getShortUrl(String longUrl){
JSONObject param = new JSONObject();
param.put("action", "long2short");
param.put("long_url", longUrl);
String result = WXHttpUtil.postJson(String.format(QRCODE.SHORT_URL, accessToken), param.toJSONString());
log.info("长链接转短链接返回信息:{}",result);
return JSONObject.parseObject(result, ShortUrl.class);
}
}