|
|
@@ -11,6 +11,13 @@ import org.apache.commons.lang.StringUtils;
|
|
|
import p2.pao.PaoRemote;
|
|
|
import p2.pao.PaoSetRemote;
|
|
|
import p2.util.P2Exception;
|
|
|
+import sun.misc.BASE64Encoder;
|
|
|
+
|
|
|
+import java.io.ByteArrayOutputStream;
|
|
|
+import java.io.InputStream;
|
|
|
+import java.net.HttpURLConnection;
|
|
|
+import java.net.MalformedURLException;
|
|
|
+import java.net.URL;
|
|
|
|
|
|
public class MyHyconfirmationorder extends Controller {
|
|
|
|
|
|
@@ -179,5 +186,40 @@ public class MyHyconfirmationorder extends Controller {
|
|
|
return getReturnObject_err(e.getMessage()).toString();
|
|
|
}
|
|
|
}
|
|
|
+ /**图片转base64**/
|
|
|
+ public String imagetobase64(){
|
|
|
+ JSONObject where = content.getJSONObject("where");
|
|
|
+ String s[] = {"url"};
|
|
|
+ for (String s1 : s) {
|
|
|
+ if (!where.containsKey(s1) && !StringUtils.isBlank(where.getString(s1)))
|
|
|
+ return getReturnObject_err("缺少" + s1 + "参数").toString();
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ final ByteArrayOutputStream data = new ByteArrayOutputStream();
|
|
|
+ String strNetImageToBase64;
|
|
|
+ URL url = null;
|
|
|
+ url = new URL(where.getString("url"));
|
|
|
+ final byte[] by = new byte[1024];
|
|
|
+ // 创建链接
|
|
|
+ final HttpURLConnection conn = (HttpURLConnection) url.openConnection();
|
|
|
+ conn.setRequestMethod("GET");
|
|
|
+ conn.setConnectTimeout(5000);
|
|
|
+
|
|
|
+ InputStream is = conn.getInputStream();
|
|
|
+ // 将内容读取内存中
|
|
|
+ int len = -1;
|
|
|
+ while ((len = is.read(by)) != -1) {
|
|
|
+ data.write(by, 0, len);
|
|
|
+ }
|
|
|
+ // 对字节数组Base64编码
|
|
|
+ BASE64Encoder encoder = new BASE64Encoder();
|
|
|
+ strNetImageToBase64 = encoder.encode(data.toByteArray());
|
|
|
+ return getReturnObject_suc(strNetImageToBase64,false).toString();
|
|
|
+ } catch (Exception e) {
|
|
|
+ return getReturnObject_err(e.getMessage()).toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
}
|