|
@@ -1,11 +1,14 @@
|
|
|
package com.shuishuo.app.core_module.trade.view.ui.activity;
|
|
package com.shuishuo.app.core_module.trade.view.ui.activity;
|
|
|
|
|
|
|
|
import android.content.Context;
|
|
import android.content.Context;
|
|
|
|
|
+import android.content.Intent;
|
|
|
import android.os.Bundle;
|
|
import android.os.Bundle;
|
|
|
|
|
+import android.util.Log;
|
|
|
import android.view.View;
|
|
import android.view.View;
|
|
|
import android.widget.ImageView;
|
|
import android.widget.ImageView;
|
|
|
import android.widget.TextView;
|
|
import android.widget.TextView;
|
|
|
|
|
|
|
|
|
|
+import com.google.gson.Gson;
|
|
|
import com.shuishuo.app.R;
|
|
import com.shuishuo.app.R;
|
|
|
import com.shuishuo.app.cache.AccountCache;
|
|
import com.shuishuo.app.cache.AccountCache;
|
|
|
import com.shuishuo.app.common.util.net.INet;
|
|
import com.shuishuo.app.common.util.net.INet;
|
|
@@ -15,6 +18,17 @@ import com.shuishuo.app.common.util.pay.PayUtil;
|
|
|
import com.shuishuo.app.common.util.pay.PaymentListener;
|
|
import com.shuishuo.app.common.util.pay.PaymentListener;
|
|
|
import com.shuishuo.app.common.views.BaseToolbar;
|
|
import com.shuishuo.app.common.views.BaseToolbar;
|
|
|
import com.shuishuo.app.impl.SheishuoUI;
|
|
import com.shuishuo.app.impl.SheishuoUI;
|
|
|
|
|
+import com.shuishuo.app.main.model.Extras;
|
|
|
|
|
+import com.shuishuo.app.wxapi.WXPayEntryActivity;
|
|
|
|
|
+import com.tencent.mm.opensdk.constants.ConstantsAPI;
|
|
|
|
|
+import com.tencent.mm.opensdk.modelbase.BaseReq;
|
|
|
|
|
+import com.tencent.mm.opensdk.modelbase.BaseResp;
|
|
|
|
|
+import com.tencent.mm.opensdk.modelpay.PayReq;
|
|
|
|
|
+import com.tencent.mm.opensdk.openapi.IWXAPI;
|
|
|
|
|
+import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
|
|
|
|
|
+import com.tencent.mm.opensdk.openapi.WXAPIFactory;
|
|
|
|
|
+
|
|
|
|
|
+import org.json.JSONObject;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* Created by KN on 2017/8/31.
|
|
* Created by KN on 2017/8/31.
|
|
@@ -23,7 +37,9 @@ import com.shuishuo.app.impl.SheishuoUI;
|
|
|
public class PayMethodActivity extends SheishuoUI implements PaymentListener{
|
|
public class PayMethodActivity extends SheishuoUI implements PaymentListener{
|
|
|
|
|
|
|
|
public final static String MONEY = "money";
|
|
public final static String MONEY = "money";
|
|
|
|
|
+ public static boolean wxPaySuccess = false;
|
|
|
|
|
|
|
|
|
|
+ private IWXAPI msgApi;
|
|
|
|
|
|
|
|
private String TAG = this.getClass().getSimpleName();
|
|
private String TAG = this.getClass().getSimpleName();
|
|
|
private Context context = this;
|
|
private Context context = this;
|
|
@@ -54,6 +70,8 @@ public class PayMethodActivity extends SheishuoUI implements PaymentListener{
|
|
|
|
|
|
|
|
void init(){
|
|
void init(){
|
|
|
|
|
|
|
|
|
|
+ wxPaySuccess = false;
|
|
|
|
|
+
|
|
|
BaseToolbar toolbar = findView(R.id.toolbar);
|
|
BaseToolbar toolbar = findView(R.id.toolbar);
|
|
|
toolbar.setTitle("谁说收银台");
|
|
toolbar.setTitle("谁说收银台");
|
|
|
toolbar.setBackOnClickListener(new View.OnClickListener() {
|
|
toolbar.setBackOnClickListener(new View.OnClickListener() {
|
|
@@ -65,7 +83,9 @@ public class PayMethodActivity extends SheishuoUI implements PaymentListener{
|
|
|
|
|
|
|
|
moneyTxt.setText(""+money+"元");
|
|
moneyTxt.setText(""+money+"元");
|
|
|
|
|
|
|
|
- pay.init(context,PayMethodActivity.this);
|
|
|
|
|
|
|
+ msgApi = WXAPIFactory.createWXAPI(this, WXPayEntryActivity.APPID);
|
|
|
|
|
+
|
|
|
|
|
+ pay.init(context, PayMethodActivity.this);
|
|
|
|
|
|
|
|
alipayImg.setOnClickListener(new View.OnClickListener() {
|
|
alipayImg.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
@Override
|
|
@@ -87,10 +107,77 @@ public class PayMethodActivity extends SheishuoUI implements PaymentListener{
|
|
|
wechatImg.setOnClickListener(new View.OnClickListener() {
|
|
wechatImg.setOnClickListener(new View.OnClickListener() {
|
|
|
@Override
|
|
@Override
|
|
|
public void onClick(View v) {
|
|
public void onClick(View v) {
|
|
|
- showToast(context,"功能暂未开放");
|
|
|
|
|
|
|
+
|
|
|
|
|
+ net.wxpay(String.valueOf(money), new ResponseCallback() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onSuccess(final Object object) {
|
|
|
|
|
+ getHandler().post(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ payWX((String) object);
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void onFailed(String error) {
|
|
|
|
|
+ showToast(context,"创建订单失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
});
|
|
});
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
|
|
+ private void payWX(String response)
|
|
|
|
|
+ {
|
|
|
|
|
+ try
|
|
|
|
|
+ {
|
|
|
|
|
+ Log.d("paywx", response);
|
|
|
|
|
+ JSONObject res = new JSONObject(response);
|
|
|
|
|
+ int code = res.getInt("c");
|
|
|
|
|
+ if(code == 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ JSONObject data = res.getJSONObject("d");
|
|
|
|
|
+
|
|
|
|
|
+ PayReq request = new PayReq();
|
|
|
|
|
+ request.appId = data.getString("appid");
|
|
|
|
|
+ request.partnerId = data.getString("partnerid");
|
|
|
|
|
+ request.prepayId= data.getString("prepayid");
|
|
|
|
|
+ request.packageValue = data.getString("package");
|
|
|
|
|
+ request.nonceStr= data.getString("noncestr");
|
|
|
|
|
+ request.timeStamp= data.getString("timestamp");
|
|
|
|
|
+ request.sign= data.getString("sign");
|
|
|
|
|
+ msgApi.sendReq(request);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ showToast(context,"创建订单失败.");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ catch (Exception e)
|
|
|
|
|
+ {
|
|
|
|
|
+ e.printStackTrace();
|
|
|
|
|
+ showToast(context,"创建订单失败..");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ @Override
|
|
|
|
|
+ protected void onResume() {
|
|
|
|
|
+ super.onResume();
|
|
|
|
|
+ if(wxPaySuccess)
|
|
|
|
|
+ {
|
|
|
|
|
+ double originMoney = Double.parseDouble(AccountCache.getAccount().getCoin());
|
|
|
|
|
+ String nowMoney = String.valueOf(originMoney + money);
|
|
|
|
|
+ AccountCache.getAccount().setCoin(nowMoney);
|
|
|
|
|
+ Log.e("WXResult", nowMoney+" "+AccountCache.getAccount().getCoin());
|
|
|
|
|
+
|
|
|
|
|
+ getHandler().postDelayed(new Runnable() {
|
|
|
|
|
+ @Override
|
|
|
|
|
+ public void run() {
|
|
|
|
|
+ finish();
|
|
|
|
|
+ }
|
|
|
|
|
+ }, 1500);
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|