123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101 |
- 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);
- }
- }
|