Просмотр исходного кода

use token in app with same user_id

hanjing лет назад: 6
Родитель
Сommit
fbe4a82934

+ 9 - 0
app/src/main/java/com/sheep/gamegroup/util/Jump2View.java

@@ -1105,6 +1105,15 @@ public class Jump2View {
         context.startActivity(intent);
     }
 
+    public void goRechargeResult(Context context, String resultStatus, String gowhere, String orderNO, String msg) {
+        Intent intent = new Intent(context, RechargeResultAct.class);
+        intent.putExtra("payCode", resultStatus);
+        intent.putExtra("gowhere", gowhere);
+        intent.putExtra("orderno", orderNO);
+        intent.putExtra("errMsg", msg);
+        context.startActivity(intent);
+    }
+
     /**
      * 跳到充值页面
      *

+ 30 - 0
app/src/main/java/com/sheep/gamegroup/view/activity/ActPay.java

@@ -12,14 +12,17 @@ import com.ipaynow.plugin.manager.route.dto.ResponseParams;
 import com.ipaynow.plugin.manager.route.impl.ReceivePayResult;
 import com.sheep.gamegroup.absBase.BaseActivity;
 import com.sheep.gamegroup.model.entity.BaseMessage;
+import com.sheep.gamegroup.model.entity.UserEntity;
 import com.sheep.gamegroup.model.entity.WebParams;
 import com.sheep.gamegroup.model.util.SheepSubscriber;
 import com.sheep.gamegroup.util.CommonUtil;
 import com.sheep.gamegroup.util.Constant;
+import com.sheep.gamegroup.util.DataUtil;
 import com.sheep.gamegroup.util.Jump2View;
 import com.sheep.gamegroup.util.QQUtil;
 import com.sheep.jiuyan.samllsheep.Config;
 import com.sheep.jiuyan.samllsheep.SheepApp;
+import com.sheep.jiuyan.samllsheep.utils.SpUtils;
 import com.tencent.mm.opensdk.constants.ConstantsAPI;
 import com.tencent.mm.opensdk.modelpay.PayResp;
 
@@ -78,8 +81,27 @@ public class ActPay extends BaseActivity {
 
     }
 
+    private String checkToken() {
+        if (TextUtils.isEmpty(token)) {
+            return "";
+        } else {
+            String tokenPrev = DataUtil.getInstance().getUserId() + "@";
+            if (token.startsWith(tokenPrev)) {
+                return SpUtils.getToken(this);
+            } else {
+                return "";
+            }
+        }
+    }
+
     @Override
     public void initData() {
+        UserEntity user = DataUtil.getInstance().getUserEntity();
+        if (user == null) {
+            Jump2View.getInstance().goRechargeResult(this, "9001", from_package, null, "请先登录");
+            finish();
+            return;
+        }
         Intent intent = getIntent();
         Bundle bundle = intent.getExtras();
         if (bundle != null) {
@@ -87,6 +109,14 @@ public class ActPay extends BaseActivity {
             pay_type = bundle.getString("pay_type");
             from_package = bundle.getString("from_package");
             token = bundle.getString("token");
+            String tokenPrev = user.getId() + "@";
+            if (token.startsWith(tokenPrev)) {
+                token = SpUtils.getToken(this);
+            } else {
+                Jump2View.getInstance().goRechargeResult(this, "9001", from_package, null, "游戏与小绵羊用户信息不一致");
+                finish();
+                return;
+            }
             if (TextUtils.isEmpty(pay_type) || PAY_TYPE_COIN.equals(pay_type)) {
                 String url = Config.getUrlByPath(Config.PATH_DIRECTIONAL_PAY + "?authorization=" + token + "&order=" + order_no + "&ssnocache=1");
                 WebParams webParams = new WebParams(url, "支付").setShowTitle(false).setForResult(true).setAction(Constant.INTENT_PAY);

+ 6 - 1
app/src/main/java/com/sheep/gamegroup/view/activity/RechargeAct.java

@@ -127,6 +127,11 @@ public class RechargeAct extends BaseActivity {
     @Override
     public void initData() {
         UserEntity user = DataUtil.getInstance().getUserEntity();
+        if (user == null) {
+            Jump2View.getInstance().goRechargeResult(RechargeAct.this, "9002", fromPackage, null, "请登录");
+            finish();
+            return;
+        }
         sheep_no_view.append(user.getInvitation_code());
         nickname_view.append(user.getNickname());
         addDatas();
@@ -190,7 +195,7 @@ public class RechargeAct extends BaseActivity {
                 getRechargePayway();
             } else {
                 String result = "9001";
-                Jump2View.getInstance().goRechargeResult(RechargeAct.this, result, fromPackage, null);
+                Jump2View.getInstance().goRechargeResult(RechargeAct.this, result, fromPackage, null, "游戏与小绵羊用户信息不一致");
             }
         } else {
             showProgress();

+ 7 - 1
app/src/main/java/com/sheep/gamegroup/view/activity/RechargeResultAct.java

@@ -28,7 +28,7 @@ public class RechargeResultAct extends BaseActivity {
     @BindView(R.id.tv_recharge_result_pay)
     TextView tvRechargeResultPay;
 
-    private String gowhere, orderno, resultStatus;
+    private String gowhere, orderno, resultStatus, errMsg;
 
     @Override
     protected int getLayoutId() {
@@ -48,6 +48,9 @@ public class RechargeResultAct extends BaseActivity {
                     .setTitle(this, "交易失败")
                     .setTitleFinish(this);
             tvRechargeResultState.setText("交易失败");
+            if (!TextUtils.isEmpty(errMsg)) {
+                tvRechargeResultState.append(": " + errMsg);
+            }
             new DrawablesHelper(tvRechargeResultState).direction(DrawablesHelper.LEFT).drawable(R.mipmap.delete_x_red_img).commit();
         }
         if (getIntent().hasExtra("gowhere")) {
@@ -56,6 +59,9 @@ public class RechargeResultAct extends BaseActivity {
         if (getIntent().hasExtra("orderno")) {
             orderno = getIntent().getStringExtra("orderno");
         }
+        if (getIntent().hasExtra("errMsg")) {
+            errMsg = getIntent().getStringExtra("errMsg");
+        }
     }
 
     @Override