2 Коміти 359a19a5ea ... be77051ba3

Автор SHA1 Опис Дата
  chenritian be77051ba3 完成支付宝支付 2 тижнів тому
  chenritian c28577c2fe 微信支付和登录成功回调 2 тижнів тому

+ 68 - 1
entry/oh-package-lock.json5

@@ -7,9 +7,16 @@
   "ATTENTION": "THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.",
   "specifiers": {
     "@abner/log@^1.0.5": "@abner/log@1.0.5",
+    "@alipay/blueshieldsdk@../oh_modules/.ohpm/@cashier_alipay+cashiersdk@15.8.42/oh_modules/@cashier_alipay/cashiersdk/lib/blueshieldsdk-1.0.30.har": "@alipay/blueshieldsdk@../oh_modules/.ohpm/@cashier_alipay+cashiersdk@15.8.42/oh_modules/@cashier_alipay/cashiersdk/lib/blueshieldsdk-1.0.30.har",
+    "@cashier_alipay/cashiersdk@^15.8.16": "@cashier_alipay/cashiersdk@15.8.42",
     "@ibestservices/ibest-ui@^2.1.2": "@ibestservices/ibest-ui@2.2.5",
     "@ohos/axios@^2.2.4": "@ohos/axios@2.2.7",
-    "@tencent/wechat_open_sdk@^1.0.14": "@tencent/wechat_open_sdk@1.0.16"
+    "@ohos/crypto-js@^2.0.4": "@ohos/crypto-js@2.0.5",
+    "@taobao-ohos/utdid_sdk@../oh_modules/.ohpm/@cashier_alipay+cashiersdk@15.8.42/oh_modules/@cashier_alipay/cashiersdk/lib/utdid_sdk-1.2.5.har": "@taobao-ohos/utdid_sdk@../oh_modules/.ohpm/@cashier_alipay+cashiersdk@15.8.42/oh_modules/@cashier_alipay/cashiersdk/lib/utdid_sdk-1.2.5.har",
+    "@tencent/wechat_open_sdk@^1.0.14": "@tencent/wechat_open_sdk@1.0.16",
+    "libblueshield.so@../oh_modules/.ohpm/@alipay+blueshieldsdk@qgf9fllog8tazdv8uop120fy3saz8l+7jb55+sipesk=/oh_modules/@alipay/blueshieldsdk/src/main/cpp/types/libblueshield": "libblueshield.so@../oh_modules/.ohpm/@alipay+blueshieldsdk@qgf9fllog8tazdv8uop120fy3saz8l+7jb55+sipesk=/oh_modules/@alipay/blueshieldsdk/src/main/cpp/types/libblueshield",
+    "libutdid_native.so@../oh_modules/.ohpm/@taobao-ohos+utdid_sdk@ecjyoomnzz6zaipo1koz9+avemnpw7+togfp5uwrtiu=/oh_modules/@taobao-ohos/utdid_sdk/src/main/cpp/types/libutdid_native": "libutdid_native.so@../oh_modules/.ohpm/@taobao-ohos+utdid_sdk@ecjyoomnzz6zaipo1koz9+avemnpw7+togfp5uwrtiu=/oh_modules/@taobao-ohos/utdid_sdk/src/main/cpp/types/libutdid_native",
+    "pako@^2.1.0": "pako@2.1.0"
   },
   "packages": {
     "@abner/log@1.0.5": {
@@ -19,6 +26,28 @@
       "resolved": "https://ohpm.openharmony.cn/ohpm/@abner/log/-/log-1.0.5.har",
       "registryType": "ohpm"
     },
+    "@alipay/blueshieldsdk@../oh_modules/.ohpm/@cashier_alipay+cashiersdk@15.8.42/oh_modules/@cashier_alipay/cashiersdk/lib/blueshieldsdk-1.0.30.har": {
+      "name": "",
+      "version": "1.0.30",
+      "integrity": "",
+      "resolved": "",
+      "registryType": "local",
+      "dependencies": {
+        "libblueshield.so": "file:./src/main/cpp/types/libblueshield"
+      }
+    },
+    "@cashier_alipay/cashiersdk@15.8.42": {
+      "name": "",
+      "version": "15.8.42",
+      "integrity": "sha512-ALbTruDona1pSOrg7GizPTzrQRdFppYU1y6VKBLj8PrmdCtV2nMBzvAbFxzg8Ixm2rch3gBw4OnHB8gkrw+htw==",
+      "resolved": "https://ohpm.openharmony.cn/ohpm/@cashier_alipay/cashiersdk/-/cashiersdk-15.8.42.har",
+      "registryType": "ohpm",
+      "dependencies": {
+        "@taobao-ohos/utdid_sdk": "file:./lib/utdid_sdk-1.2.5.har",
+        "@alipay/blueshieldsdk": "file:./lib/blueshieldsdk-1.0.30.har",
+        "pako": "^2.1.0"
+      }
+    },
     "@ibestservices/ibest-ui@2.2.5": {
       "name": "",
       "version": "2.2.5",
@@ -33,12 +62,50 @@
       "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/axios/-/axios-2.2.7.har",
       "registryType": "ohpm"
     },
+    "@ohos/crypto-js@2.0.5": {
+      "name": "",
+      "version": "2.0.5",
+      "integrity": "sha512-QPW+vxSambzep39qnnvGLk2lItqPqt+HBTo7FsTdL9edv3z35h4D80ClnEPNPfXQzIp8DgVDMIgbAWa1hWq8ug==",
+      "resolved": "https://ohpm.openharmony.cn/ohpm/@ohos/crypto-js/-/crypto-js-2.0.5.har",
+      "registryType": "ohpm"
+    },
+    "@taobao-ohos/utdid_sdk@../oh_modules/.ohpm/@cashier_alipay+cashiersdk@15.8.42/oh_modules/@cashier_alipay/cashiersdk/lib/utdid_sdk-1.2.5.har": {
+      "name": "",
+      "version": "1.2.5",
+      "integrity": "",
+      "resolved": "",
+      "registryType": "local",
+      "dependencies": {
+        "libutdid_native.so": "file:./src/main/cpp/types/libutdid_native",
+        "@ohos/crypto-js": "^2.0.4"
+      }
+    },
     "@tencent/wechat_open_sdk@1.0.16": {
       "name": "",
       "version": "1.0.16",
       "integrity": "sha512-/vqcsHFQlQ1UWybijbRTWlT+9BqRUcE/FWsYayEoVwreOeGJ/pdxNHZFkU0EManYRxnqzLoL4SB8HGJNdsm9TA==",
       "resolved": "https://ohpm.openharmony.cn/ohpm/@tencent/wechat_open_sdk/-/wechat_open_sdk-1.0.16.har",
       "registryType": "ohpm"
+    },
+    "libblueshield.so@../oh_modules/.ohpm/@alipay+blueshieldsdk@qgf9fllog8tazdv8uop120fy3saz8l+7jb55+sipesk=/oh_modules/@alipay/blueshieldsdk/src/main/cpp/types/libblueshield": {
+      "name": "libblueshield.so",
+      "version": "1.0.8",
+      "resolved": "",
+      "registryType": "local"
+    },
+    "libutdid_native.so@../oh_modules/.ohpm/@taobao-ohos+utdid_sdk@ecjyoomnzz6zaipo1koz9+avemnpw7+togfp5uwrtiu=/oh_modules/@taobao-ohos/utdid_sdk/src/main/cpp/types/libutdid_native": {
+      "name": "libutdid_native.so",
+      "version": "0.0.1",
+      "resolved": "",
+      "registryType": "local"
+    },
+    "pako@2.1.0": {
+      "name": "",
+      "version": "2.1.0",
+      "integrity": "sha512-w+eufiZ1WuJYgPXbV/PO3NCMEc3xqylkKHzp8bxp1uW4qaSNQUkwmLLEc3kKsfz8lpV1F8Ht3U1Cm+9Srog2ug==",
+      "resolved": "https://ohpm.openharmony.cn/ohpm/pako/-/pako-2.1.0.tgz",
+      "shasum": "266cc37f98c7d883545d11335c00fbd4062c9a86",
+      "registryType": "ohpm"
     }
   }
 }

+ 2 - 1
entry/oh-package.json5

@@ -9,7 +9,8 @@
     "@ibestservices/ibest-ui": "^2.1.2",
     "@ohos/axios": "^2.2.4",
     "@tencent/wechat_open_sdk": "^1.0.14",
-    "@abner/log": "^1.0.5"
+    "@abner/log": "^1.0.5",
+    "@cashier_alipay/cashiersdk": "^15.8.16"
   }
 }
 

+ 65 - 0
entry/src/main/ets/model/JDBModel.ets

@@ -1,6 +1,71 @@
+import { Pay } from '@cashier_alipay/cashiersdk';
+import { IBestToast } from '@ibestservices/ibest-ui';
+import { PayReq, SendAuthReq } from '@tencent/wechat_open_sdk';
+import { ContextHelper } from '../utils/ContextHelper';
+import { WechatUtil } from '../utils/wechat/WechatUtil';
+import { jDBViewModel } from '../viewModels/JDBViewModel';
+import { WeChatPayParams } from './WechatModel';
+import { BusinessError } from '@kit.BasicServicesKit';
+import { ALiPayUtil } from '../utils/alipay/ALiPayUtil';
+
 export interface RunH5Param {
   // type: 'wx_login'-微信登录 | 'wx_pay'-微信支付 | 'ali_login' 支付宝登录授权 | 'ali_pay' 支付宝支付
   // 'wx_share' - 微信分享 | 'wx_pyq_share' -微信朋友圈分享 | 'qq_share'QQ分享 | 'wx_code' - 微信授权码获取
   type: 'wx_login' | 'wx_pay' | 'ali_login' | 'ali_pay' | 'wx_share' | 'wx_pyq_share' | 'qq_share' | 'wx_code'
   data: ESObject
+}
+
+
+export class JDBObj {
+  async handleWeChatLogin(): Promise<void> {
+    try {
+      let req = new SendAuthReq();
+      req.isOption1 = false;
+      req.nonAutomatic = true;
+      req.scope = 'snsapi_userinfo'; //应用授权作用域,获取用户个人信息则填写 snsapi_userinfo (只能填 snsapi_userinfo)
+      req.state = 'none';
+      req.transaction = 'test123';
+      let finished = await WechatUtil.getWechatApi().sendReq(ContextHelper.UIAbilityContext, req);
+    } catch (error) {
+      IBestToast.show({ message: '微信登录失败,请重试', type: 'fail' });
+    }
+  }
+
+  async handleWeChatPay(param: WeChatPayParams) {
+    let req = new PayReq()
+    req.appId = param.appid
+    req.partnerId = param.partnerid
+    req.prepayId = param.prepayid
+    req.packageValue = param.package
+    req.nonceStr = param.noncestr
+    req.timeStamp = param.timestamp.toString()
+    req.sign = param.sign
+    await WechatUtil.getWechatApi().sendReq(ContextHelper.UIAbilityContext, req)
+  }
+
+
+  handleAlipayAuthorization() {
+    ALiPayUtil.startAuthorization()
+  }
+
+
+  handleAliPay(orderInfo: string) {
+    IBestToast.show({ message: '开始支付:请求参数:' + orderInfo })
+    new Pay().pay(orderInfo, false).then((result) => {
+      let message =
+        `resultStatus: ${result.get('resultStatus')} memo: ${result.get('memo')} result: ${result.get('result')}`;
+      console.log(message);
+      jDBViewModel.runJavaScript({
+        type: 'ali_pay',
+        data: result.get('resultStatus')
+      })
+      IBestToast.show({ message: message })
+    }).catch((error: BusinessError) => {
+      console.log(error.message);
+      IBestToast.show({
+        message: error.message,
+        duration: 2000,
+      })
+    });
+  }
 }

+ 4 - 33
entry/src/main/ets/model/WechatModel.ets

@@ -1,8 +1,11 @@
+import { Pay } from '@cashier_alipay/cashiersdk';
 import { IBestToast } from '@ibestservices/ibest-ui';
 import { PayReq, SendAuthReq } from '@tencent/wechat_open_sdk';
 import { ALiPayUtil } from '../utils/alipay/ALiPayUtil';
 import { ContextHelper } from '../utils/ContextHelper';
 import { WechatUtil } from '../utils/wechat/WechatUtil';
+import { BusinessError } from '@kit.BasicServicesKit';
+import { jDBViewModel } from '../viewModels/JDBViewModel';
 
 export interface AccessTokenResponse {
   access_token: string;
@@ -29,7 +32,7 @@ export interface AccessTokenResult {
 /**
  * 微信支付参数接口
  */
-interface WeChatPayParams {
+export interface WeChatPayParams {
   /**
    * 应用ID(AppID)
    */
@@ -67,35 +70,3 @@ interface WeChatPayParams {
 }
 
 
-export class JDBObj {
-  async handleWeChatLogin(): Promise<void> {
-    try {
-      let req = new SendAuthReq();
-      req.isOption1 = false;
-      req.nonAutomatic = true;
-      req.scope = 'snsapi_userinfo'; //应用授权作用域,获取用户个人信息则填写 snsapi_userinfo (只能填 snsapi_userinfo)
-      req.state = 'none';
-      req.transaction = 'test123';
-      let finished = await WechatUtil.getWechatApi().sendReq(ContextHelper.UIAbilityContext, req);
-    } catch (error) {
-      IBestToast.show({ message: '微信登录失败,请重试', type: 'fail' });
-    }
-  }
-
-  async handleWeChatPay(param: WeChatPayParams) {
-    let req = new PayReq()
-    req.appId = param.appid
-    req.partnerId = param.partnerid
-    req.prepayId = param.prepayid
-    req.packageValue = param.package
-    req.nonceStr = param.noncestr
-    req.timeStamp = param.timestamp.toString()
-    req.sign = param.sign
-    await WechatUtil.getWechatApi().sendReq(ContextHelper.UIAbilityContext, req)
-  }
-
-
-  handleAlipayAuthorization(){
-    ALiPayUtil.startAuthorization()
-  }
-}

+ 18 - 2
entry/src/main/ets/pages/Index.ets

@@ -8,6 +8,7 @@ import { yTBindSheet } from '../utils/YTBindSheet';
 import { ContextHelper } from '../utils/ContextHelper';
 import { YTRequest } from '../apis/YTRequest';
 import { jDBViewModel } from '../viewModels/JDBViewModel';
+import { router } from '@kit.ArkUI';
 
 @Entry
 @Component
@@ -57,6 +58,21 @@ struct Index {
     await jDBViewModel.checkDeviceChannel()
   }
 
+  onBackPress(): boolean | void {
+    if (jDBViewModel.isExistDeviceChannel && jDBViewModel.flag) {
+      try {
+        if (jDBViewModel.controller.accessBackward()) {
+          jDBViewModel.controller.backward()
+        }
+      } catch (e) {
+        router.back()
+      }
+    } else {
+      router.back()
+    }
+    return true
+  }
+
   build() {
     Stack() {
 
@@ -73,8 +89,8 @@ struct Index {
             .javaScriptProxy({
               object: jDBViewModel.jDBItem,
               name: "jDBItem",
-              methodList: ["handleWeChatLogin", "handleWeChatPay", "handleAlipayAuthorization"],
-              asyncMethodList: ["handleWeChatLogin", "handleWeChatPay", "handleAlipayAuthorization"],
+              methodList: ["handleWeChatLogin", "handleWeChatPay", "handleAlipayAuthorization", "handleAliPay"],
+              asyncMethodList: ["handleWeChatLogin", "handleWeChatPay", "handleAlipayAuthorization", "handleAliPay"],
               controller: jDBViewModel.controller,
             })
         }

+ 9 - 0
entry/src/main/ets/utils/wechat/WXApiEventHandlerImpl.ets

@@ -2,6 +2,7 @@ import { IBestToast } from '@ibestservices/ibest-ui';
 import { BaseReq, BaseResp, LaunchFromWXReq, PayResp, SendAuthResp, WXApiEventHandler } from '@tencent/wechat_open_sdk';
 import { WechatApi } from '../../apis/WechatApi';
 import { AccessTokenResponse, WeChatExtData } from '../../model/WechatModel';
+import { jDBViewModel } from '../../viewModels/JDBViewModel';
 import { YTLog } from '../YTLog';
 import { WechatUtil } from './WechatUtil';
 
@@ -58,6 +59,10 @@ export class WXApiEventHandlerImpl implements WXApiEventHandler {
     if (resp instanceof SendAuthResp) {
       if (resp.errCode === 0 && resp.code) {
         YTLog.info(TAG, `WeChat login success, code: ${resp.code}`);
+        jDBViewModel.runJavaScript({
+          type: 'wx_login',
+          data: resp
+        })
         this.handleLoginSuccess(resp.code);
       } else {
         YTLog.error(TAG, `WeChat login failed, errCode: ${resp.errCode}, errStr: ${resp.errStr}`);
@@ -66,6 +71,10 @@ export class WXApiEventHandlerImpl implements WXApiEventHandler {
       }
     } else if (resp instanceof PayResp) {
       // 支付回调处理
+      jDBViewModel.runJavaScript({
+        type: 'wx_pay',
+        data: resp
+      })
       console.log('微信支付结果', JSON.stringify(resp));
     }
   }

+ 1 - 2
entry/src/main/ets/viewModels/JDBViewModel.ets

@@ -3,8 +3,7 @@ import { DeviceChannelQuery } from '../model/StatusModel'
 import { SystemUtil } from '../utils/SystemUtil'
 import { webview } from '@kit.ArkWeb'
 import { DEBUG } from 'BuildProfile'
-import { JDBObj } from '../model/WechatModel'
-import { RunH5Param } from '../model/JDBModel'
+import { JDBObj, RunH5Param } from '../model/JDBModel'
 
 @ObservedV2
 export class JDBViewModel {