调整上传客服头像接口
This commit is contained in:
parent
3f0a120047
commit
c0f0705519
@ -107,11 +107,8 @@ public class Netty4HttpClient extends AbstractHttpClient {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
InetSocketAddress address = new InetSocketAddress(
|
InetSocketAddress address = useProxy ? (InetSocketAddress) params.getProxy().address() : new InetSocketAddress(
|
||||||
InetAddress.getByName(uri.getHost()), getPort(uri));
|
InetAddress.getByName(uri.getHost()), getPort(uri));
|
||||||
if (useProxy) {
|
|
||||||
address = (InetSocketAddress) params.getProxy().address();
|
|
||||||
}
|
|
||||||
bootstrap.connect(address).syncUninterruptibly()
|
bootstrap.connect(address).syncUninterruptibly()
|
||||||
.addListener(listener);
|
.addListener(listener);
|
||||||
response = future.get();
|
response = future.get();
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
package com.foxinmy.weixin4j.mp;
|
package com.foxinmy.weixin4j.mp;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -168,9 +167,8 @@ public class WeixinProxy {
|
|||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public TokenHolder getTicketHolder(TicketType ticketType) {
|
public TokenHolder getTicketHolder(TicketType ticketType) {
|
||||||
return new TokenHolder(new WeixinTicketCreator(this.appId,
|
return new TokenHolder(new WeixinTicketCreator(this.appId, ticketType,
|
||||||
ticketType, this.tokenHolder),
|
this.tokenHolder), this.tokenHolder.getTokenStorager());
|
||||||
this.tokenHolder.getTokenStorager());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -560,22 +558,23 @@ public class WeixinProxy {
|
|||||||
/**
|
/**
|
||||||
* 上传客服头像
|
* 上传客服头像
|
||||||
*
|
*
|
||||||
* @param id
|
* @param accountId
|
||||||
* 完整客服账号,格式为:账号前缀@公众号微信号
|
* 完整客服账号,格式为:账号前缀@公众号微信号
|
||||||
* @param headimg
|
* @param is
|
||||||
* 头像图片文件必须是jpg格式,推荐使用640*640大小的图片以达到最佳效果
|
* 头像图片文件必须是jpg格式,推荐使用640*640大小的图片以达到最佳效果
|
||||||
|
* @param fileName
|
||||||
|
* 文件名 为空时将自动生成
|
||||||
* @return 处理结果
|
* @return 处理结果
|
||||||
* @throws WeixinException
|
|
||||||
* @throws IOException
|
|
||||||
* @see com.foxinmy.weixin4j.mp.api.CustomApi
|
* @see com.foxinmy.weixin4j.mp.api.CustomApi
|
||||||
|
* @throws WeixinException
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/9/6fff6f191ef92c126b043ada035cc935.html#.E5.AE.A2.E6.9C.8D.E7.AE.A1.E7.90.86.E6.8E.A5.E5.8F.A3.E8.BF.94.E5.9B.9E.E7.A0.81.E8.AF.B4.E6.98.8E">客服管理接口返回码</a>
|
* href="http://mp.weixin.qq.com/wiki/9/6fff6f191ef92c126b043ada035cc935.html#.E5.AE.A2.E6.9C.8D.E7.AE.A1.E7.90.86.E6.8E.A5.E5.8F.A3.E8.BF.94.E5.9B.9E.E7.A0.81.E8.AF.B4.E6.98.8E">客服管理接口返回码</a>
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/9/6fff6f191ef92c126b043ada035cc935.html#.E4.B8.8A.E4.BC.A0.E5.AE.A2.E6.9C.8D.E5.A4.B4.E5.83.8F">上传客服头像</a>
|
* href="http://mp.weixin.qq.com/wiki/9/6fff6f191ef92c126b043ada035cc935.html#.E4.B8.8A.E4.BC.A0.E5.AE.A2.E6.9C.8D.E5.A4.B4.E5.83.8F">上传客服头像</a>
|
||||||
*/
|
*/
|
||||||
public JsonResult uploadAccountHeadimg(String id, File headimg)
|
public JsonResult uploadAccountHeadimg(String accountId, InputStream is,
|
||||||
throws WeixinException, IOException {
|
String fileName) throws WeixinException {
|
||||||
return customApi.uploadAccountHeadimg(id, headimg);
|
return customApi.uploadAccountHeadimg(accountId, is, fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
package com.foxinmy.weixin4j.mp.api;
|
package com.foxinmy.weixin4j.mp.api;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.InputStream;
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -11,8 +9,9 @@ import com.alibaba.fastjson.JSON;
|
|||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.alibaba.fastjson.TypeReference;
|
import com.alibaba.fastjson.TypeReference;
|
||||||
import com.foxinmy.weixin4j.exception.WeixinException;
|
import com.foxinmy.weixin4j.exception.WeixinException;
|
||||||
import com.foxinmy.weixin4j.http.apache.ByteArrayBody;
|
import com.foxinmy.weixin4j.http.ContentType;
|
||||||
import com.foxinmy.weixin4j.http.apache.FormBodyPart;
|
import com.foxinmy.weixin4j.http.apache.FormBodyPart;
|
||||||
|
import com.foxinmy.weixin4j.http.apache.InputStreamBody;
|
||||||
import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
import com.foxinmy.weixin4j.http.weixin.JsonResult;
|
||||||
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
import com.foxinmy.weixin4j.http.weixin.WeixinResponse;
|
||||||
import com.foxinmy.weixin4j.model.Pageable;
|
import com.foxinmy.weixin4j.model.Pageable;
|
||||||
@ -22,7 +21,8 @@ import com.foxinmy.weixin4j.mp.model.KfAccount;
|
|||||||
import com.foxinmy.weixin4j.mp.model.KfSession;
|
import com.foxinmy.weixin4j.mp.model.KfSession;
|
||||||
import com.foxinmy.weixin4j.token.TokenHolder;
|
import com.foxinmy.weixin4j.token.TokenHolder;
|
||||||
import com.foxinmy.weixin4j.util.DigestUtil;
|
import com.foxinmy.weixin4j.util.DigestUtil;
|
||||||
import com.foxinmy.weixin4j.util.IOUtil;
|
import com.foxinmy.weixin4j.util.FileUtil;
|
||||||
|
import com.foxinmy.weixin4j.util.ObjectId;
|
||||||
import com.foxinmy.weixin4j.util.StringUtil;
|
import com.foxinmy.weixin4j.util.StringUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -186,28 +186,33 @@ public class CustomApi extends MpApi {
|
|||||||
/**
|
/**
|
||||||
* 上传客服头像
|
* 上传客服头像
|
||||||
*
|
*
|
||||||
* @param id
|
* @param accountId
|
||||||
* 完整客服账号,格式为:账号前缀@公众号微信号
|
* 完整客服账号,格式为:账号前缀@公众号微信号
|
||||||
* @param headimg
|
* @param is
|
||||||
* 头像图片文件必须是jpg格式,推荐使用640*640大小的图片以达到最佳效果
|
* 头像图片文件必须是jpg格式,推荐使用640*640大小的图片以达到最佳效果
|
||||||
|
* @param fileName
|
||||||
|
* 文件名 为空时将自动生成
|
||||||
* @return 处理结果
|
* @return 处理结果
|
||||||
* @throws WeixinException
|
* @throws WeixinException
|
||||||
* @throws IOException
|
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/9/6fff6f191ef92c126b043ada035cc935.html#.E5.AE.A2.E6.9C.8D.E7.AE.A1.E7.90.86.E6.8E.A5.E5.8F.A3.E8.BF.94.E5.9B.9E.E7.A0.81.E8.AF.B4.E6.98.8E">客服管理接口返回码</a>
|
* href="http://mp.weixin.qq.com/wiki/9/6fff6f191ef92c126b043ada035cc935.html#.E5.AE.A2.E6.9C.8D.E7.AE.A1.E7.90.86.E6.8E.A5.E5.8F.A3.E8.BF.94.E5.9B.9E.E7.A0.81.E8.AF.B4.E6.98.8E">客服管理接口返回码</a>
|
||||||
* @see <a
|
* @see <a
|
||||||
* href="http://mp.weixin.qq.com/wiki/9/6fff6f191ef92c126b043ada035cc935.html#.E4.B8.8A.E4.BC.A0.E5.AE.A2.E6.9C.8D.E5.A4.B4.E5.83.8F">上传客服头像</a>
|
* href="http://mp.weixin.qq.com/wiki/9/6fff6f191ef92c126b043ada035cc935.html#.E4.B8.8A.E4.BC.A0.E5.AE.A2.E6.9C.8D.E5.A4.B4.E5.83.8F">上传客服头像</a>
|
||||||
*/
|
*/
|
||||||
public JsonResult uploadAccountHeadimg(String id, File headimg)
|
public JsonResult uploadAccountHeadimg(String accountId, InputStream is,
|
||||||
throws WeixinException, IOException {
|
String fileName) throws WeixinException {
|
||||||
|
if (StringUtil.isBlank(fileName)) {
|
||||||
|
fileName = ObjectId.get().toHexString();
|
||||||
|
}
|
||||||
|
if (StringUtil.isBlank(FileUtil.getFileExtension(fileName))) {
|
||||||
|
fileName = String.format("%s.jpg", fileName);
|
||||||
|
}
|
||||||
Token token = tokenHolder.getToken();
|
Token token = tokenHolder.getToken();
|
||||||
String custom_uploadheadimg_uri = getRequestUri("custom_uploadheadimg_uri");
|
String custom_uploadheadimg_uri = getRequestUri("custom_uploadheadimg_uri");
|
||||||
byte[] bytes = IOUtil.toByteArray(new FileInputStream(headimg));
|
WeixinResponse response = weixinExecutor.post(String.format(
|
||||||
WeixinResponse response = weixinExecutor.post(
|
custom_uploadheadimg_uri, token.getAccessToken(), accountId),
|
||||||
String.format(custom_uploadheadimg_uri, token.getAccessToken(),
|
new FormBodyPart("media", new InputStreamBody(is,
|
||||||
id),
|
ContentType.IMAGE_JPG.getMimeType(), fileName)));
|
||||||
new FormBodyPart("media", new ByteArrayBody(bytes, headimg
|
|
||||||
.getName())));
|
|
||||||
|
|
||||||
return response.getAsJsonResult();
|
return response.getAsJsonResult();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
package com.foxinmy.weixin4j.mp.test;
|
package com.foxinmy.weixin4j.mp.test;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
@ -74,7 +75,8 @@ public class CustomTest extends TokenTest {
|
|||||||
@Test
|
@Test
|
||||||
public void uploadAccountHeadimg() throws WeixinException, IOException {
|
public void uploadAccountHeadimg() throws WeixinException, IOException {
|
||||||
JsonResult result = customApi.uploadAccountHeadimg(
|
JsonResult result = customApi.uploadAccountHeadimg(
|
||||||
"temp1@canyidianzhang", new File("/Users/jy/Music/简谱/风动草.jpg"));
|
"temp1@canyidianzhang", new FileInputStream(new File(
|
||||||
|
"/Users/jy/Music/简谱/风动草.jpg")), "风动草.jpg");
|
||||||
Assert.assertEquals(0, result.getCode());
|
Assert.assertEquals(0, result.getCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user