|
|
@@ -0,0 +1,47 @@
|
|
|
+import { AFAuthServiceResponse, AFService, AFServiceCenter, AFServiceParams, AFWantParams } from '@alipay/afservicesdk';
|
|
|
+import Want from '@ohos.app.ability.Want';
|
|
|
+import BuildProfile from 'BuildProfile';
|
|
|
+import { jDBViewModel } from '../../viewModels/JDBViewModel';
|
|
|
+
|
|
|
+export class ALiPayUtil {
|
|
|
+ static ALIPAY_APP_ID = '2021006101646784'
|
|
|
+ static scheme = 'jdb'
|
|
|
+ static scope = 'auth_user'
|
|
|
+ static state = 'init'
|
|
|
+
|
|
|
+ static handleResponse(want: Want) {
|
|
|
+ return AFServiceCenter.handleResponse(want);
|
|
|
+ }
|
|
|
+
|
|
|
+ static startAuthorization() {
|
|
|
+ /**
|
|
|
+ * 构建参数
|
|
|
+ */
|
|
|
+ let bizParams = new Map<string, string>()
|
|
|
+ let url =
|
|
|
+ encodeURIComponent(`https://authweb.alipay.com/auth?auth_type=PURE_OAUTH_SDK&app_id=${ALiPayUtil.ALIPAY_APP_ID}&scope=${ALiPayUtil.scope}&state=${ALiPayUtil.state}`)
|
|
|
+ bizParams.set("url", url);
|
|
|
+
|
|
|
+ let backWant: AFWantParams = {
|
|
|
+ bundleName: BuildProfile.BUNDLE_NAME, //接入方应用包名
|
|
|
+ moduleName: "entry",
|
|
|
+ abilityName: "EntryAbility"
|
|
|
+ }
|
|
|
+
|
|
|
+ let params =
|
|
|
+ new AFServiceParams(bizParams, false, true, ALiPayUtil.scheme, backWant, (response: AFAuthServiceResponse) => {
|
|
|
+ //授权返回值
|
|
|
+ console.info('=========ALiPay response=' + JSON.stringify(response));
|
|
|
+ //TODO 调用业务方接口处理授权结果
|
|
|
+ jDBViewModel.runJavaScript({
|
|
|
+ type: 'ali_login',
|
|
|
+ data: response
|
|
|
+ })
|
|
|
+ })
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 调用授权
|
|
|
+ */
|
|
|
+ AFServiceCenter.call(AFService.AFServiceAuth, params)
|
|
|
+ }
|
|
|
+}
|