WXPayEntryActivity.uts 1.6 KB
Newer Older
DCloud-yyl's avatar
DCloud-yyl 已提交
1 2 3 4 5 6 7 8 9
import Activity from 'android.app.Activity';
import IWXAPIEventHandler from 'com.tencent.mm.opensdk.openapi.IWXAPIEventHandler';
import BaseReq from 'com.tencent.mm.opensdk.modelbase.BaseReq';
import BaseResp from 'com.tencent.mm.opensdk.modelbase.BaseResp';
import ConstantsAPI from 'com.tencent.mm.opensdk.constants.ConstantsAPI';
import Bundle from 'android.os.Bundle'
import WXAPIFactory from 'com.tencent.mm.opensdk.openapi.WXAPIFactory';
import {Wxpay} from './Wxpay';
import R from 'uts.sdk.modules.uniPaymentWxpay.R';
DCloud-yyl's avatar
DCloud-yyl 已提交
10
const defaultErrorCode : number = 700000
DCloud-yyl's avatar
DCloud-yyl 已提交
11
const errorCodeMap : Map<number, number> = new Map([
DCloud-yyl's avatar
DCloud-yyl 已提交
12 13
	[-1, 701100],
	[-2, 700601]
DCloud-yyl's avatar
DCloud-yyl 已提交
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
])
export class WXPayEntryActivity extends Activity implements IWXAPIEventHandler {
	constructor() {
		super()
	}

	override onCreate(savedInstanceState : Bundle | null) {
		super.onCreate(savedInstanceState)
		let api = WXAPIFactory.createWXAPI(this, '');
		api.handleIntent(this.getIntent(), this);
	}
	override onResp(resp : BaseResp) : void {
		let options=Wxpay.mOptions
		console.log("mOptions",options)
		if (resp.getType() == ConstantsAPI.COMMAND_PAY_BY_WX) {
			if (resp.errCode == 0) {
				let res : RequestPaymentSuccess = {
					data: resp
				}
				options.success?.(res)
				options.complete?.(res)
			} else {
				let code = errorCodeMap[resp.errCode];
				if (code == null) {
					code = defaultErrorCode
				}
				let err = new RequestPaymentFailImpl(code.toInt());
				options.fail?.(err)
				options.complete?.(err)
			}
		}
		this.finish();
		this.overridePendingTransition(0,R.anim.uni_wxpay_out_top);
	}
	override onReq(req : BaseReq) {
		this.finish();
	}
};