All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.tmsps.ne4weixin.api.ShortUrlAPI Maven / Gradle / Ivy

There is a newer version: 3.2.2.3
Show newest version
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);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy