Skip to content

Commit

Permalink
V1.3版本
Browse files Browse the repository at this point in the history
  • Loading branch information
szvone committed Feb 25, 2019
1 parent d787222 commit caf4561
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 17 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,10 @@
+ 因本系统为无数据库模式,所以在war包的同级目录会生成一个vone.txt来保存系统配置,请您不要删除该文件,否则会导致配置丢失,系统会恢复默认配置!

## 更新记录
+ v1.3(2019.02.25)
+ 很抱歉搜狗图床已经失效,无法使用外链,更新去除搜狗图床
+ 新浪图床上传程序更新,修复新浪图床上传提示服务器繁忙的BUG

+ v1.2(2018.10.28)
+ 添加新浪图床支持

Expand Down
27 changes: 18 additions & 9 deletions src/main/java/cn/szvone/img/service/VoneService.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,13 @@ public ApiRes doUpload(String key, String imgBase64){


if (voneConfig.getType() == 1){
String res = SougouApi.uploadImg(imgBase64);
if (res.indexOf("http")>=0){
return ApiResultUtil.success(res);
}else{
return ApiResultUtil.error("上传失败");
}
return ApiResultUtil.error("搜狗图床已停止服务");
// String res = SougouApi.uploadImg(imgBase64);
// if (res.indexOf("http")>=0){
// return ApiResultUtil.success(res);
// }else{
// return ApiResultUtil.error("上传失败");
// }
}else if (voneConfig.getType() == 2){
String ck = voneConfig.getSinaCookie();
long lastTime = 0;
Expand All @@ -48,9 +49,11 @@ public ApiRes doUpload(String key, String imgBase64){

if (ck.equals("") || lastTime+10800000<new Date().getTime()){
ck = SinaApi.login(voneConfig.getSinaUser(),voneConfig.getSinaPass());

if (ck.equals("")){
return ApiResultUtil.error("新浪账号密码有误");
}

voneConfig.setSinaCookie(ck);
if (lastTime+10800000<new Date().getTime()){
voneConfig.setSinaUpdateTime(String.valueOf(new Date().getTime()));
Expand All @@ -62,7 +65,13 @@ public ApiRes doUpload(String key, String imgBase64){
if (res.indexOf("http")>=0){
return ApiResultUtil.success(res);
}else{
return ApiResultUtil.error("上传失败");
if (res.equals("-1")){
voneConfig.setSinaCookie("");
save(voneConfig);
return ApiResultUtil.error("新浪账号密码有误");
}else {
return ApiResultUtil.error("服务器繁忙,错误代码:"+res);
}
}
}

Expand Down Expand Up @@ -139,7 +148,7 @@ private VoneConfig getVoneConfig(){
try {
voneConfig.setType(Integer.valueOf(VoneUtil.getSubString(myIni,"Type=[","]")));
}catch (Exception e){
voneConfig.setType(1);
voneConfig.setType(2);
}
voneConfig.setSinaUpdateTime(VoneUtil.getSubString(myIni,"SinaUpdateTime=[","]"));
}else{
Expand All @@ -148,7 +157,7 @@ private VoneConfig getVoneConfig(){
voneConfig.setSinaPass("");
voneConfig.setSinaCookie("");
voneConfig.setKey("123456");
voneConfig.setType(1);
voneConfig.setType(2);
voneConfig.setSinaUpdateTime("");
save(voneConfig);
}
Expand Down
24 changes: 19 additions & 5 deletions src/main/java/cn/szvone/img/util/SinaApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class SinaApi {
public static String uploadImg(String imgBase64,String ck) {


String url = "http://picupload.service.weibo.com/interface/pic_upload.php?mime=image%2Fjpeg&data=base64&url=0&markpos=1&logo=&nick=0&marks=1&app=miniblog";
String url = "http://picupload.weibo.com/interface/pic_upload.php?cb=https%3A%2F%2Fweibo.com%2Faj%2Fstatic%2Fupimgback.html%3F_wv%3D5%26callback%3DSTK_ijax_1551096206285100&mime=image%2Fjpeg&data=base64&url=weibo.com%2Fu%2F5734329255&markpos=1&logo=1&nick=&marks=0&app=miniblog&s=rdxt&pri=0&file_source=2";



Expand All @@ -28,6 +28,9 @@ public static String uploadImg(String imgBase64,String ck) {
InputStream inputStream = null;
//尝试发送请求
try {

//ck="SUB=_2A25xd6e5DeRhGeNJ6FYS8ifOzjmIHXVSBJ5xrDV8PUNbmtAKLXnHkW9NS8PUgB08tOVmchSobLjjnfy2-EM-svCC;";

u = new URL(url);
con = (HttpURLConnection) u.openConnection();
con.setRequestMethod("POST");
Expand All @@ -46,6 +49,7 @@ public static String uploadImg(String imgBase64,String ck) {
//读取返回内容
inputStream = con.getInputStream();

//https://weibo.com/aj/static/upimgback.html?_wv=5&callback=STK_ijax_1551096206285100&ret=1&pid=006g4EZxgy1g0iz2blozoj30u01aogo9

InputStreamReader isr = new InputStreamReader(inputStream);
BufferedReader bufr = new BufferedReader(isr);
Expand All @@ -57,13 +61,23 @@ public static String uploadImg(String imgBase64,String ck) {
ret+=str;
}

ret = VoneUtil.getSubString(ret,"\"name\":\"pic_1\",\"pid\":\"","\"}");
System.out.println(con.getHeaderField("location"));

if (!ret.equals("")){
ret = "http://wx1.sinaimg.cn/large/"+ret+".jpg";
String retCode = VoneUtil.getSubString(con.getHeaderField("location")+"&","&ret=","&");
if (retCode.equals("1")){
ret = VoneUtil.getSubString(con.getHeaderField("location")+"&","&pid=","&");

if (!ret.equals("")){
ret = "http://wx1.sinaimg.cn/large/"+ret+".jpg";
}
}else {
ret = retCode;
}





} catch (Exception e) {
e.printStackTrace();
} finally {
Expand Down Expand Up @@ -110,7 +124,7 @@ public static String login(String user,String pass){
while ((str = bufr.readLine()) != null) {
ret+=str;
}

System.out.println(ret);
//获取cookie
Map<String, List<String>> map=con.getHeaderFields();
Set<String> set=map.keySet();
Expand Down
2 changes: 1 addition & 1 deletion src/main/webapp/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ <h3 class="masthead-brand">超简图床</h3>
<div class="inner cover">
<h1 class="cover-heading">轻量级图床程序(JAVA版)</h1>
<p class="lead">
本套图床程序提供搜狗CDN存储(无需配置)、新浪CDN存储(需要配置新浪账号【推荐】)、本地存储(需占用服务器空间)三种模式可供切换选择,对外提供Api接口实现图片上传,一键搭建,简单调用!</p>
本套图床程序提供搜狗CDN存储(无需配置【已经失效】)、新浪CDN存储(需要配置新浪账号【推荐】)、本地存储(需占用服务器空间)三种模式可供切换选择,对外提供Api接口实现图片上传,一键搭建,简单调用!</p>
<p class="lead">
<a href="https://github.com/szvone/imgApiJava" target="_blank" class="btn btn-lg btn-default">获取程序</a>
</p>
Expand Down
4 changes: 2 additions & 2 deletions src/main/webapp/setting.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ <h1 class="cover-heading">系统配置</h1>
<div class="input-group">
<div class="input-group-addon">运行模式</div>
<select class="form-control" id="type">
<option value="1">搜狗CDN(无需配置,默认模式</option>
<option value="1" disabled>搜狗CDN(无需配置,已经失效</option>
<option value="2">新浪CDN(需要账号,推荐使用)</option>
<option value="3" disabled>下一版加入】本地存储(占用空间,保证安全)</option>
<option value="3" disabled>请使用PHP版】本地存储(占用空间,保证安全)</option>
</select>
</div>
</div>
Expand Down

0 comments on commit caf4561

Please sign in to comment.