package com.wsj.Imgdt3; import android.app.Activity; import android.content.Context; import android.content.Intent; import android.os.Bundle; import android.util.Log; import android.widget.Toast; 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 com.unity3d.player.UnityPlayer; public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler{ public static String GameObjectName; public static String CallBackFuncName; private static final String TAG = "WXPayEntryActivity"; private IWXAPI api; public static String wxAPPID = "wxd9772f42f126413f"; // 在调用微信支付处,设置该变量值 @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.wx_pay_result); // api = WXAPIFactory.createWXAPI(this, wxAPPID); api.handleIntent(getIntent(), this); //UnityPlayer.UnitySendMessage(GameObjectName,CallBackFuncName,"微信API_ING"); } @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) { showText("onPayFinish, errCode = " + resp.errCode); if (resp.errCode != 0 && resp.errCode != -2) { showToast(this, "微信支付失败, errCode:" + resp.errCode); } if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) { // AlertDialog.Builder builder = new AlertDialog.Builder(this); // builder.setTitle("提示"); // builder.setMessage("微信支付结果:" + resp.errCode); // builder.show(); if(resp.errCode == 0) { // PaySuccess(this); // 可在此处,添加应用自己的支付结果统计相关逻辑 showToast(this, "微信支付成功"); } else if(resp.errCode == -2) showToast(this, "用户取消支付"); else showToast(this, "支付失败,其他异常情形" ); } showToast(this, GameObjectName + "," + CallBackFuncName ); UnityPlayer.UnitySendMessage(GameObjectName, CallBackFuncName, "" + resp.errCode); this.finish(); } /** 输出log信息 */ public static void showText(final String info) { Log.d(TAG, info); } /** 输出Toast消息 */ private void showToast(Context context, final String info) { Toast.makeText(context, info, Toast.LENGTH_SHORT).show(); Log.d(TAG, info); } }