6***@qq.com
6***@qq.com
  • 发布:2020-09-18 18:14
  • 更新:2020-09-18 18:14
  • 阅读:802

uniapp android studio打包 微信支付可以起调但是返回不了结果

分类:uni-app

package com.jiandanhuiwu.wxapi;

import com.jiandanhuiwu.Constants;
import com.jiandanhuiwu.R;
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.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import static com.jiandanhuiwu.R.string.pay_result_callback_msg;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler{

private IWXAPI api;  

@Override  
public void onCreate(Bundle savedInstanceState) {  
    super.onCreate(savedInstanceState);  
    setContentView(R.layout.pay_result);  
    api = WXAPIFactory.createWXAPI(this, Constants.APP_ID);  
    api.handleIntent(getIntent(), this);  
}  

@Override  
protected void onNewIntent(Intent intent) {  
    super.onNewIntent(intent);  
    setIntent(intent);  
    api.handleIntent(intent, this);  
}  

@Override  
public void onReq(BaseReq req) {  
}  

@Override  
public void onResp(BaseResp resp) {  

// if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
// AlertDialog.Builder builder = new AlertDialog.Builder(this);
// builder.setTitle(R.string.app_tip);
// builder.setMessage(getString(pay_result_callback_msg, new Object[]{String.valueOf(resp.errCode)}));
// builder.show();
// }

    if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {  
        int errCode = resp.errCode;  
        if (errCode == -1) {/*支付失败*/  
            Toast.makeText(this, "支付失败", Toast.LENGTH_SHORT).show();  
        } else if (errCode == 0) {/*支付成功*/  
            Toast.makeText(this, "支付成功", Toast.LENGTH_SHORT).show();  
        } else if (errCode == -2) {/*取消支付*/  
            Toast.makeText(this, "取消支付", Toast.LENGTH_SHORT).show();  
        }  
        overridePendingTransition(0,0);  
        finish();  
    }  
}  

}

2020-09-18 18:14 负责人:无 分享
已邀请:

该问题目前已经被锁定, 无法添加新回复