unity接入微信支付java代码

版权声明:本文为博主原创文章,转载请注明出处。 https://blog.csdn.net/qq563129582/article/details/83386529

微信支付

需要自己打出jar包,供unity调用。
贴出java代码,以作日后参考

WXEntryActivity

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.hnsh.qlmj.wxapi;

import android.content.Intent;
import android.widget.Toast;
import cn.sharesdk.wechat.utils.WXAppExtendObject;
import cn.sharesdk.wechat.utils.WXMediaMessage;
import cn.sharesdk.wechat.utils.WechatHandlerActivity;

public class WXEntryActivity extends WechatHandlerActivity {

    public WXEntryActivity() {
    }
    
    public void onGetMessageFromWXReq(WXMediaMessage msg) {
        if(msg != null) {
            Intent iLaunchMyself = this.getPackageManager().getLaunchIntentForPackage(this.getPackageName());
            this.startActivity(iLaunchMyself);
        }
    }
    
    public void onShowMessageFromWXReq(WXMediaMessage msg) {
        if(msg != null && msg.mediaObject != null && msg.mediaObject instanceof WXAppExtendObject) {
            WXAppExtendObject obj = (WXAppExtendObject)msg.mediaObject;
            Toast.makeText(this, obj.extInfo, 0).show();
        }
    }
}

WXPayEntryActivity

//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by Fernflower decompiler)
//

package com.hnsh.qlmj.wxapi;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import com.tencent.mm.sdk.modelbase.BaseReq;
import com.tencent.mm.sdk.modelbase.BaseResp;
import com.tencent.mm.sdk.openapi.IWXAPI;
import com.tencent.mm.sdk.openapi.IWXAPIEventHandler;
import com.tencent.mm.sdk.openapi.WXAPIFactory;
import com.unity3d.player.UnityPlayer;

public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
    private static final String TAG = "Unity";
    private String APP_ID = "wxef5d09e3283e5202";
    private IWXAPI api;

    public WXPayEntryActivity() {
    }

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        this.api = WXAPIFactory.createWXAPI(this, this.APP_ID);
        this.api.handleIntent(this.getIntent(), this);
    }

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

    public void onReq(BaseReq req) {
    }

    public void onResp(BaseResp resp) {
        Log.d("Unity", "onPayFinish, errCode = " + resp.errCode);
        if(resp.getType() == 5) {
            int retCode = resp.errCode;
            UnityPlayer.UnitySendMessage("GameRoot", "WXPayCallback", String.valueOf(retCode));
            this.finish();
        }
    }
}

猜你喜欢

转载自blog.csdn.net/qq563129582/article/details/83386529

相关文章