使用联通WO+平台的长短地址转换接口

xuening0494 2015-05-22 09:00:41
在很多限制内容字数的消息发送平台里边,当要发送的内容含有url地址时,通常都需要url长地址转换成短地址在进行发送,微博就是这么做的。wo+平台给我们提供了一个这样的便利的接口。当然要使用这个接口,首先需要注册成为wo+平台开发者,并且签约相关的接口。

相关的接口有两个:
1.将长地址转换为短地址
请求URI:
https://open.wo.com.cn/openapi/longurlintoshort/v1.0
请求头里边需要带的参数:
Authorization,对应的值为:appKey="appKey值",token="token值"
Content-Type,对应的值为:application/json;charset=UTF-8
Accept,对应的值为:application/json
请求消息体参数:
longUrl,对应需要转换的长地址
返回结果:
{
"resultCode":"0",
"resultDescription":"请求成功。",
"shortUrl":"http://akn.so/m2Gf3X"
}

2.短地址查询对应的长地址
请求URI:
https://open.wo.com.cn/openapi/checkoutlongurl/v1.0
请求头里边需要带的参数:
Authorization,对应的值为:appKey="appKey值",token="token值"
Content-Type,对应的值为:application/json;charset=UTF-8
Accept,对应的值为:application/json
请求消息体参数:
shortUrl,转换后的短地址
返回结果:
{
"resultCode":"0",
"resultDescription":"成功。",
"longUrl":http://open.189.cn/
}

如下是以volley做为该网络请求的实例:
String url = "https://open.wo.com.cn/openapi/longurlintoshort/v1.0";

Response.Listener<String> successListener = new Response.Listener<String>(){
@Override
public void onResponse(String response) {
//ToDo 处理返回结果
}
};

Response.ErrorListener errorListener = new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {

}
};

StringRequest stringRequest = new StringRequest(Request.Method.POST, url, successListener,errorListener){
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String,String> map = new HashMap<String,String>();
map.put("Authorization","appKey=\"xxxx\",token=\"xxxx\"");
map.put("Content-Type","application/json;charset=UTF-8");
map.put("Accept","application/json");
return map;
}

@Override
protected Map<String, String> getParams() throws AuthFailureError {
HashMap<String,String> map = new HashMap<String,String>();
map.put("longUrl","http://www.baidu.com/xxx_f_djfasdffdfffffffadf");
return map;
}
};

...全文
179 回复 打赏 收藏 转发到动态 举报
写回复
用AI写文章
回复
切换为时间正序
请发表友善的回复…
发表回复

170

社区成员

发帖
与我相关
我的任务
社区描述
应用内计费、短信API、话费支付、移动支付、计费SDK、二维码API、计费API、计费接口、wo+开放平台、wo+能力共享平台、wo+梦工厂、联通能力开放
社区管理员
  • 联通WO+开放平台社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧