unity接入微信支付java程式碼
阿新 • • 發佈:2018-12-17
微信支付
需要自己打出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();
}
}
}