使用的SDK版本:api 'com.tencent.mm.opensdk:wechat-sdk-android:6.8.0'
Activity路径和包名:
Activity代码:
public class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
private IWXAPI api;
private ElementNative unity;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
unity = new ElementNative();
unity.init();
unity.sendLog("wechat pay entry activity create");
api = WXAPIFactory.createWXAPI(this,getString(R.string.wechat_app_id));
api.handleIntent(getIntent(),this);
}
protected void onNewIntent(Intent intent)
{
super.onNewIntent(intent);
setIntent(intent);
api.handleIntent(intent,this);
}
@Override
public void onReq(BaseReq baseReq) {
}
@Override
public void onResp(BaseResp resp) {
unity.sendLog("wechat pay response type: " + resp.getType());
if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX)
{
try{
JSONObject data = new JSONObject();
data.put("code", resp.errCode);
data.put("message", resp.errStr);
data.put("transaction", resp.transaction);
unity.sendJson("wechat_pay_result", data);
}
catch (JSONException e)
{
unity.sendLog("wechat pay response json:failed. " + e.getMessage());
}
}
finish();
}
}
Menifest.xml:
<activity
android:name=".wxapi.WXPayEntryActivity"
android:label="@string/app_name"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:taskAffinity="net.sourceforge.simcpux"
android:launchMode="singleTop"
android:exported="true"/>
返回商户之后没有任何反应,在Oncreate里面写的打印log也没有打印。