75
-        }
76
-        if(loginTask.getStatus()== AsyncTask.Status.RUNNING){
77
-            loginTask.cancel(true);
78
-        }
79
-        loginTask = null;
175
+    private void wxLogin(HashMap<String, String> params) {
176
+
177
+        loginTask = new HttpPostTask(params) {
178
+
179
+            String lensmanId;
180
+            String message;
181
+
182
+            @Override
183
+            protected boolean parseResponse(String response) {
184
+                try {
185
+                    JSONObject json = new JSONObject(response);
186
+                    int status = json.getInt("status");
187
+                    if (status == 200) {
188
+                        JSONObject info = json.getJSONObject("data");
189
+                        lensmanId = info.getString("user_id");
190
+                        return true;
191
+                    } else {
192
+                        message = json.getString("message");
193
+                    }
194
+                } catch (Exception e) {
195
+                    e.printStackTrace();
196
+                }
197
+                return false;
198
+            }
199
+
200
+            @Override
201
+            protected void onPostFail() {
202
+                super.onPostFail();
203
+                listener.onInteractFail(message);
204
+            }
205
+
206
+            @Override
207
+            protected void onPostSuccess() {
208
+                super.onPostSuccess();
209
+                listener.onInteractSuccess(lensmanId);
210
+            }
211
+        };
212
+        loginTask.executeOnExecutor(ThreadExecutor.getInstance().getExecutor(), UrlContainer.WX_LOGIN_URL);
80 213
     }
81 214
 
82 215
 }

+ 11 - 7
app/src/main/java/ai/pai/lensman/login/LoginPresenter.java

@@ -1,6 +1,7 @@
1 1
 package ai.pai.lensman.login;
2 2
 
3 3
 import android.content.Context;
4
+import android.text.TextUtils;
4 5
 
5 6
 import com.tencent.mm.sdk.modelmsg.SendAuth;
6 7
 import com.tencent.mm.sdk.openapi.IWXAPI;
@@ -26,13 +27,6 @@ public class LoginPresenter implements LoginContract.Presenter,BaseInteractor.In
26 27
 
27 28
     @Override
28 29
     public void login() {
29
-        view.showProgressView();
30
-        interactor = new LoginInteractor(this);
31
-        interactor.startJob();
32
-    }
33
-
34
-    @Override
35
-    public void start() {
36 30
         IWXAPI api = WXAPIFactory.createWXAPI(context, APP_ID, true);
37 31
         api.registerApp(APP_ID);
38 32
         SendAuth.Req req = new SendAuth.Req();
@@ -42,6 +36,16 @@ public class LoginPresenter implements LoginContract.Presenter,BaseInteractor.In
42 36
     }
43 37
 
44 38
     @Override
39
+    public void start() {
40
+        String wxCode = Preferences.getInstance(context).getWXCode();
41
+        if(!TextUtils.isEmpty(wxCode)){
42
+            view.showProgressView();
43
+            interactor = new LoginInteractor(wxCode,this);
44
+            interactor.startJob();
45
+        }
46
+    }
47
+
48
+    @Override
45 49
     public void stop() {
46 50
         if(interactor!=null){
47 51
             interactor.cancelJob();

+ 21 - 1
app/src/main/java/ai/pai/lensman/utils/UrlContainer.java

@@ -13,7 +13,27 @@ public class UrlContainer {
13 13
 
14 14
     public static final String SESSION_IDS_CREATE = HOST_URL+"uuid";
15 15
 
16
-    public static final String PHOTO_UPLOAD_URL = HOST_URL+"photos/upload";
16
+    /**
17
+     * user_id  # 用户唯一标识
18
+     * nickname  # 用户昵称
19
+     * session_id  # SESSION唯一标识
20
+     * photo_id  # 照片唯一标识
21
+     * photo  # @File 需要上传的照片
22
+     * current_id  # 当前以获取照片最大id,不传默认为-1
23
+     */
24
+    public static final String PHOTO_UPLOAD_URL = HOST_URL+"l/upload";
25
+
26
+    /**
27
+     * unionid  # 摄影师微信授权 Unionid
28
+     * openid  # 摄影师微信授权 Openid
29
+     * sex  # 性别
30
+     * nickname or screen_name  # 昵称,Android 和 iOS 貌似不同
31
+     * headimgurl or profile_image_url  # 头像,Android 和 iOS 貌似不同
32
+     * country  # 国家
33
+     * province  # 省份
34
+     * city  # 城市
35
+     */
36
+    public static final String WX_LOGIN_URL = HOST_URL+"l/wx/authorize";
17 37
 
18 38
 
19 39
 

+ 3 - 0
app/src/main/java/ai/pai/lensman/wxapi/WXEntryActivity.java

@@ -11,6 +11,8 @@ import com.tencent.mm.sdk.openapi.IWXAPI;
11 11
 import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
12 12
 import com.tencent.mm.sdk.openapi.WXAPIFactory;
13 13
 
14
+import ai.pai.lensman.db.Preferences;
15
+
14 16
 public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
15 17
 
16 18
     private IWXAPI api;
@@ -42,6 +44,7 @@ public class WXEntryActivity extends Activity implements IWXAPIEventHandler {
42 44
         if(resp instanceof SendAuth.Resp){
43 45
             SendAuth.Resp newResp = (SendAuth.Resp) resp;
44 46
             String code = newResp.code;
47
+            Preferences.getInstance(this).setWXCode(code);
45 48
         }
46 49
     }
47 50
 

pai2 - Gogs: Go Git Service

拍爱

thumbnail_utils.py 401B

    # -*- coding: utf-8 -*- from __future__ import division try: from PIL import Image except ImportError: import Image def make_thumb(im_path, max_width=360): im = Image.open(im_path) width, height = im.size thumb_width = min(max_width, width) thumb_height = height / width * thumb_width im.thumbnail((thumb_width, thumb_height)) im.save(im_path, im.format or 'JPEG')