阿里鉴权去掉productkey判断
authorliangzhenying <867174124@qq.com>
Fri, 16 Aug 2024 07:01:57 +0000 (15:01 +0800)
committerliangzhenying <867174124@qq.com>
Fri, 16 Aug 2024 07:01:57 +0000 (15:01 +0800)
Document/AiMouseSdk接口文档.md
Document/麦吉sdk.rtf [new file with mode: 0644]
MaiJi/Mouse_Dongle接收器通信协议_v1.0_20240619.docx [new file with mode: 0644]
MaiJi/语音鼠标蓝牙通信接口v1.0_20240619.docx [new file with mode: 0644]
MouseSdk/AiMouseSdk/AiMouseSdk/AiAliAuthManager.m
MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate

index dd7784f..14ab19f 100644 (file)
@@ -2,24 +2,17 @@
 \r
 \r
 \r
-## 文档修改记录\r
+## 介绍\r
 \r
-| 版本   | 修改内容                                            | 修改人 | 修改时间   |\r
-| ------ | --------------------------------------------------- | ------ | ---------- |\r
-| 1.0.0  | 初始版本                                            | 梁振营 | 2024-03-8  |\r
-| 1.0.1  | 鼠标按键指令修改                                    | 梁振营 | 2024-03-18 |\r
-| 1.0.2  | 鉴权流程修改,只有鉴权成功了,SDK相关功能才可以使用 | 梁振营 | 2024-03-19 |\r
-| 1.0.3  | 按键指令修改                                        | 梁振营 | 2024-03-20 |\r
-| 1.0.4  | 支持USB通讯                                         | 梁振营 | 2024-04-01 |\r
-| 1.0.5  | 支持静态库.a                                        | 梁振营 | 2024-04-22 |\r
-| 1.0.6  | 增加鉴权                                            | 梁振营 | 2024-04-30 |\r
-| 1.0.13 | 鉴权流程优化                                        | 梁振营 | 2024-05-20 |\r
-| 1.0.17 | 增加命令控制录音功能                                | 梁振营 | 2024-05-28 |\r
-| 1.0.19 | 新增连接状态回调                                    | 梁振营 | 2024-05-29 |\r
-| 1.0.21 | 鉴权逻辑优化,隐藏鉴权接口                          | 梁振营 | 2024-05-31 |\r
-| 1.0.21 | 新增设置品牌接口、USB数据异常接口回调               | 梁振营 | 2024-06-06 |\r
+当前版本:v1.0.31\r
 \r
+更新内容20240816:\r
 \r
+1. 支持阿里鉴权\r
+\r
+## 环境要求\r
+\r
+MacOS 13.0\r
 \r
 \r
 \r
@@ -56,7 +49,6 @@ libz.tbd、libbz2.tbd、libiconv.tbd、liblzma5.tbd、CoreAudio.framework、Vide
 ## SDK相关接口\r
 \r
 ```objective-c\r
-\r
 /// 单利\r
 +(AiMouse *)shared;\r
 \r
@@ -195,6 +187,46 @@ libz.tbd、libbz2.tbd、libiconv.tbd、liblzma5.tbd、CoreAudio.framework、Vide
 \r
 ```\r
 \r
+## 其他类型数据\r
+\r
+```objective-c\r
+\r
+@interface AiMouseDeviceInfo : NSObject\r
+@property (nonatomic, strong) NSString *battery_power;/// 电池百分百电量,0-100\r
+@property (nonatomic, strong) NSString *CPI;/// CPI值\r
+@property (nonatomic, strong) NSString *CPI_list;/// 可设置的CPI参数列表\r
+@property (nonatomic, strong) NSString *version;///软件版本\r
+@property (nonatomic, strong) NSString *brand;/// 品牌名称\r
+@property (nonatomic, strong) NSString *sn;/// 设备序列号\r
+@property (nonatomic, strong) NSString *mac;///设备MAC地址\r
+@end\r
+\r
+typedef NS_ENUM(NSInteger,AiMouseErrorCode) {\r
+    AiMouseErrorCode_timeOut = 1001,///请求超时\r
+    AiMouseErrorCode_busy = 1002,/// 繁忙,有命令未执行完\r
+    AiMouseErrorCode_unknown = 1003,/// 未知错误\r
+};\r
+\r
+/// 日志等级\r
+typedef NS_ENUM(NSInteger,AiMouseLogLevel) {\r
+    AiMouseLogLevel_none = 0,\r
+    AiMouseLogLevel_error,\r
+    AiMouseLogLevel_info,\r
+};\r
+\r
+typedef NS_ENUM(NSInteger,AiMouseConnectType) {\r
+    AiMouseConnectType_bluetooth = 0,///蓝牙\r
+    AiMouseConnectType_hid,///hid\r
+};\r
+\r
+typedef NS_ENUM(NSInteger,AiMouseAuthState) {\r
+    AiMouseAuthState_Unknow = 0,///未知\r
+    AiMouseAuthState_Success,///鉴权成功\r
+    AiMouseAuthState_Failure///鉴权失败\r
+};\r
+\r
+```\r
+\r
 \r
 \r
 ## 蓝牙示例\r
@@ -292,7 +324,8 @@ libz.tbd、libbz2.tbd、libiconv.tbd、liblzma5.tbd、CoreAudio.framework、Vide
     if(self.didDisConnectDevice){\r
         self.didDisConnectDevice(peripheral);\r
     }\r
-    [self autoConnectDevice];\r
+//    [self aiMouseConnectStateDidChange:false];\r
+    [[AiMouse shared] didDisconnect];\r
 }\r
 - (void)centralManager:(CBCentralManager *)central didFailToConnectPeripheral:(CBPeripheral *)peripheral error:(nullable NSError *)error{\r
     [self showLog:[NSString stringWithFormat:@"连接失败。。。%@",error.description]];\r
@@ -321,15 +354,13 @@ libz.tbd、libbz2.tbd、libiconv.tbd、liblzma5.tbd、CoreAudio.framework、Vide
             [AiMouse shared].delegate = self;\r
             //切换当前连接类型\r
             [[AiMouse shared] switchConnect:AiMouseConnectType_bluetooth];\r
-            //找到鉴权特征后,一定要调用鉴权接口开始鉴权。只有鉴权通过了,sdk相关功能才可以使用\r
-            [self startAuthentication];\r
+\r
         }\r
     }\r
 }\r
 //收到蓝牙数据\r
 - (void)peripheral:(CBPeripheral *)peripheral didUpdateValueForCharacteristic:(CBCharacteristic *)characteristic error:(NSError *)error {\r
     NSData *data = characteristic.value;\r
-    [self showLog:[NSString stringWithFormat:@"[receive] %@",data]];\r
     if([characteristic.UUID.UUIDString isEqualToString:kAiUUID]){\r
         //AI数据\r
         [[AiMouse shared] sendAiDataToSdk:data];\r
@@ -341,11 +372,18 @@ libz.tbd、libbz2.tbd、libiconv.tbd、liblzma5.tbd、CoreAudio.framework、Vide
 }\r
 \r
 #pragma mark - AiDelegate\r
-\r
+/// 设备鉴权结果返回\r
+/// - Parameter authState: 鉴权状态\r
+-(void)aiMouseAuthenticationResult:(AiMouseAuthState)authState{\r
+    [self showLog:[NSString stringWithFormat:@"鉴权结果 = %@",@(authState)]];\r
+    if(self.authCallBack){\r
+        self.authCallBack(authState == AiMouseAuthState_Success);\r
+    }\r
+}\r
 /// 设备信息数据回调,需要将此数据通过设备信息特征转发给蓝牙设备\r
 /// - Parameter data: 数据\r
 -(void)aiMouseSendDeviceInfoData:(NSData *)data{\r
-    [self showLog:[NSString stringWithFormat:@"[send] %@",data]];\r
+//    [self showLog:[NSString stringWithFormat:@"[send] %@",data]];\r
     [self.connectPeripheral writeValue:data forCharacteristic:self.deviceInfoCha type:CBCharacteristicWriteWithoutResponse];\r
 }\r
 \r
@@ -375,7 +413,20 @@ libz.tbd、libbz2.tbd、libiconv.tbd、liblzma5.tbd、CoreAudio.framework、Vide
 - (void)aiMouseSendRecordData:(NSData *)data{\r
     [self.recordData appendData:data];\r
 }\r
+/// 输出日志\r
+- (void)aiMouseAddLog:(NSString *)log { \r
+//    [self showLog:log];\r
+}\r
 \r
+// 连接状态改变\r
+- (void)aiMouseConnectStateDidChange:(BOOL)connected{\r
+    if (connected) {\r
+        [[NSNotificationCenter defaultCenter] postNotificationName:kDidConnectBleNotification object:nil];\r
+    }\r
+    else{\r
+        [[NSNotificationCenter defaultCenter] postNotificationName:kDidDisconnectBleNotification object:nil];\r
+    }\r
+}\r
 #pragma mark - public\r
 /// 连接设备\r
 - (void)startScanDevice{\r
@@ -397,15 +448,7 @@ libz.tbd、libbz2.tbd、libiconv.tbd、liblzma5.tbd、CoreAudio.framework、Vide
 - (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo * _Nonnull, NSError * _Nonnull))completation{\r
     [[AiMouse shared] getDeviceInfo:completation];\r
 }\r
-/// 鉴权\r
--(void)startAuthentication{\r
-    [[AiMouse shared] startAuthentication:^(AiMouseAuthState state) {\r
-        [self showLog:[NSString stringWithFormat:@"鉴权结果 = %@",@(state)]];\r
-        if(self.authCallBack){\r
-            self.authCallBack(state == AiMouseAuthState_Success);\r
-        }\r
-    }];\r
-}\r
+\r
 #pragma mark - other\r
 //自动连接,获取已配对的蓝牙,取第一个连接\r
 - (void)autoConnectDevice{\r
@@ -510,7 +553,7 @@ const long productID = 0x8601;
 \r
 - (void)open{\r
     self.hidManager = IOHIDManagerCreate(kCFAllocatorDefault, kIOHIDOptionsTypeNone);\r
-    IOHIDManagerScheduleWithRunLoop(self.hidManager, CFRunLoopGetMain(), kCFRunLoopDefaultMode);\r
+    IOHIDManagerScheduleWithRunLoop(self.hidManager, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);\r
     IOReturn ret = IOHIDManagerOpen(self.hidManager, 0L);\r
     if (ret != kIOReturnSuccess) {\r
         NSLog(@"打开设备失败!");\r
@@ -540,28 +583,40 @@ const long productID = 0x8601;
 #pragma mark - Hid CallBack\r
 /// 匹配到设备回调\r
 static void hidAppearDevice(void *inContext,IOReturn inResult,void *inSender,IOHIDDeviceRef inIOHIDDeviceRef) {\r
-    uint32_t vid = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDVendorIDKey));\r
-    uint32_t pid = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDProductIDKey));\r
+    [[HidManager shared] showLog:[NSString stringWithFormat:@"发现设备 %@\n ",inIOHIDDeviceRef]];\r
     uint32_t PrimaryUsagePage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsagePageKey));\r
     uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsageKey));\r
-    [[HidManager shared] showLog:[NSString stringWithFormat:@"vid = %u, pid = %u, PrimaryUsagePage = %u, PrimaryUsage = %u,",vid,pid,PrimaryUsagePage,PrimaryUsage]];\r
-    [[HidManager shared] showLog:[NSString stringWithFormat:@"发现设备 %@\n ",inIOHIDDeviceRef]];\r
-    \r
-    //    PrimaryUsagePage=1 PrimaryUsage=0,设备信息\r
-    //    PrimaryUsagePage=65283 PrimaryUsage=0,ai\r
     if(PrimaryUsagePage == 1 && PrimaryUsage == 0){\r
         //设备信息\r
         [HidManager shared].deviceInfoCha = inIOHIDDeviceRef;\r
-        //开始鉴权\r
-        [[HidManager shared] startAuthentication];\r
+        [[HidManager shared] connectDevice];\r
+        //注册消息回调\r
+        unsigned char InputBuffer[128];\r
+        IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), hidReceiveData, NULL);\r
+        IOReturn ret = IOHIDDeviceOpen(inIOHIDDeviceRef, 0);\r
+        if (ret != kIOReturnSuccess) {\r
+            NSLog(@"打开设备信息失败!");\r
+        }else{\r
+            NSLog(@"打开设备信息成功!");\r
+        }\r
+        CFRetain(inIOHIDDeviceRef);\r
+        IOHIDDeviceScheduleWithRunLoop(inIOHIDDeviceRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);\r
     }\r
     else if(PrimaryUsagePage == 65283 && PrimaryUsage == 0){\r
         //ai\r
         [HidManager shared].aiCha = inIOHIDDeviceRef;\r
+        //注册消息回调\r
+        unsigned char InputBuffer[128];\r
+        IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), hidReceiveData, NULL);\r
+        IOReturn ret = IOHIDDeviceOpen(inIOHIDDeviceRef, 0);\r
+        if (ret != kIOReturnSuccess) {\r
+            NSLog(@"打开AI失败!");\r
+        }else{\r
+            NSLog(@"打开AI成功!");\r
+        }\r
+        CFRetain(inIOHIDDeviceRef);\r
+        IOHIDDeviceScheduleWithRunLoop(inIOHIDDeviceRef, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);\r
     }\r
-    //注册消息回调\r
-    unsigned char InputBuffer[128];\r
-    IOHIDDeviceRegisterInputReportCallback(inIOHIDDeviceRef, InputBuffer, sizeof(InputBuffer), hidReceiveData, NULL);\r
 }\r
 \r
 /// 设备移除回调\r
@@ -571,7 +626,9 @@ static void hidDisAppearDevice(void *inContext,IOReturn inResult,void *inSender,
     uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(inIOHIDDeviceRef, CFSTR(kIOHIDPrimaryUsageKey));\r
 \r
     if(PrimaryUsagePage == 1 && PrimaryUsage == 0){\r
-        [HidManager shared].connectStateCallBack(false);\r
+        [HidManager shared].deviceInfoCha = nil;\r
+        [HidManager shared].aiCha = nil;\r
+        [[AiMouse shared] didDisconnect];\r
     }\r
 }\r
 \r
@@ -586,11 +643,10 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe
     uint32_t PrimaryUsage = IOHIDDevGetUInt32Property(sender, CFSTR(kIOHIDPrimaryUsageKey));\r
 \r
     if(PrimaryUsagePage == 1 && PrimaryUsage == 0){\r
-        [[HidManager shared] showLog:[NSString stringWithFormat:@"收到device数据 %@",data]];\r
         [[AiMouse shared] sendDeviceDataToSdk:data];\r
+        \r
     }\r
     else if(PrimaryUsagePage == 65283 && PrimaryUsage == 0){\r
-        [[HidManager shared] showLog:[NSString stringWithFormat:@"收到AI数据 %@",data]];\r
         [[AiMouse shared] sendAiDataToSdk:data];\r
     }\r
 }\r
@@ -601,6 +657,14 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe
     [self sendData:data toDevice:self.deviceInfoCha];\r
 }\r
 \r
+/// 设备鉴权结果返回\r
+/// - Parameter authState: 鉴权状态\r
+-(void)aiMouseAuthenticationResult:(AiMouseAuthState)authState{\r
+    [self showLog:[NSString stringWithFormat:@"鉴权结果 = %@",@(authState)]];\r
+    if(self.authCallBack){\r
+        self.authCallBack(authState == AiMouseAuthState_Success);\r
+    }\r
+}\r
 /// 鼠标按键指令回调\r
 /// - Parameter data: 数据。\r
 /// 前  第一次单击31(开始录音), 第二次单击32(结束录音) , 按下21(开始录音)抬起22(结束录音)\r
@@ -626,23 +690,26 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe
 - (void)aiMouseSendRecordData:(NSData *)data{\r
     [self.recordData appendData:data];\r
 }\r
+/// 输出日志\r
+- (void)aiMouseAddLog:(NSString *)log {\r
+//    [self showLog:log];\r
+}\r
 \r
+-(void)hidDataError{\r
+    [self close];\r
+    [self open];\r
+}\r
+\r
+// 连接状态改变\r
+- (void)aiMouseConnectStateDidChange:(BOOL)connected{\r
+    [HidManager shared].connectStateCallBack(connected);\r
+}\r
 #pragma mark - public\r
--(void)startAuthentication{\r
-    //连上设备\r
-    [HidManager shared].connectStateCallBack(true);\r
+-(void)connectDevice{\r
     //设置代理\r
     [AiMouse shared].delegate = self;\r
     //切换当前连接类型\r
     [[AiMouse shared] switchConnect:AiMouseConnectType_hid];\r
-    //找到鉴权特征后,一定要调用鉴权接口开始鉴权。只有鉴权通过了,sdk相关功能才可以使用\r
-    [self showLog:@"开始鉴权"];\r
-    [[AiMouse shared] startAuthentication:^(AiMouseAuthState state) {\r
-        [self showLog:[NSString stringWithFormat:@"鉴权结果 = %@",@(state)]];\r
-        if(self.authCallBack){\r
-            self.authCallBack(state == AiMouseAuthState_Success);\r
-        }\r
-    }];\r
 }\r
 /// 获取设备信息\r
 - (void)getDeviceInfo:(void (^)(AiMouseDeviceInfo * _Nonnull, NSError * _Nonnull))completation{\r
@@ -655,7 +722,6 @@ static void hidReceiveData(void* context, IOReturn result, void* sender, IOHIDRe
         [self showLog:@"请先连上设备"];\r
         return;\r
     }\r
-    [self showLog:[NSString stringWithFormat:@"开始发送[send] %@",data]];\r
     \r
     IOReturn ret = IOHIDDeviceSetReport(device, kIOHIDReportTypeOutput, 0, data.bytes, data.length);\r
     if (ret != kIOReturnSuccess) {\r
diff --git a/Document/麦吉sdk.rtf b/Document/麦吉sdk.rtf
new file mode 100644 (file)
index 0000000..b40b3d8
--- /dev/null
@@ -0,0 +1,11 @@
+{\rtf1\ansi\ansicpg936\cocoartf2709
+\cocoatextscaling0\cocoaplatform0{\fonttbl\f0\fswiss\fcharset0 Helvetica;}
+{\colortbl;\red255\green255\blue255;}
+{\*\expandedcolortbl;;}
+\paperw11900\paperh16840\margl1440\margr1440\vieww11520\viewh8400\viewkind0
+\pard\tx720\tx1440\tx2160\tx2880\tx3600\tx4320\tx5040\tx5760\tx6480\tx7200\tx7920\tx8640\pardirnatural\partightenfactor0
+
+\f0\fs24 \cf0 \uc0\u26680 \u33455 \u24494 \u30340 \u25353 \u38190 \u21644 \u36890 \u36947 \u36319 \u23500 \u29790 \u22372 \u19981 \u19968 \u26679 \
+\
+\
+\uc0\u27888 \u20940 \u24494 \u12289 \u40614 \u21513 }
\ No newline at end of file
diff --git a/MaiJi/Mouse_Dongle接收器通信协议_v1.0_20240619.docx b/MaiJi/Mouse_Dongle接收器通信协议_v1.0_20240619.docx
new file mode 100644 (file)
index 0000000..095418a
Binary files /dev/null and "b/MaiJi/Mouse_Dongle\346\216\245\346\224\266\345\231\250\351\200\232\344\277\241\345\215\217\350\256\256_v1.0_20240619.docx" differ
diff --git a/MaiJi/语音鼠标蓝牙通信接口v1.0_20240619.docx b/MaiJi/语音鼠标蓝牙通信接口v1.0_20240619.docx
new file mode 100644 (file)
index 0000000..fd74c80
Binary files /dev/null and "b/MaiJi/\350\257\255\351\237\263\351\274\240\346\240\207\350\223\235\347\211\231\351\200\232\344\277\241\346\216\245\345\217\243v1.0_20240619.docx" differ
index b312e5a..53734ee 100644 (file)
@@ -36,18 +36,20 @@ const NSString *instanceId = @"iot-040adh4x";
 
 - (void)loginWith:(AiMouseDeviceInfo *)info{
     self.deviceInfo = info;
-    if (![info valueForKey:@"productKey"] || ![info valueForKey:@"secretKey"] || !info.sn || !info.sn) {
-        [self showLog:@"获取设备信息错误,鉴权失败!"];
-        return;
-    }
-    if([[info valueForKey:@"deviceSecret"] isKindOfClass:[NSString class]] && ([(NSString *)[info valueForKey:@"deviceSecret"] length] > 2)){
-        //已注册过,直接登录
-        [self loginRequest];
+    if ([self.deviceInfo.mac isKindOfClass:[NSString class]] && self.deviceInfo.mac.length > 0 ) {
+        if([[info valueForKey:@"deviceSecret"] isKindOfClass:[NSString class]] && ([(NSString *)[info valueForKey:@"deviceSecret"] length] > 2)){
+            //已注册过,直接登录
+            [self loginRequest];
+        }
+        else{
+            //未注册
+            [self registerReuest];
+        }
     }
     else{
-        //未注册
-        [self registerReuest];
+        [self showLog:@"获取设备信息错误,鉴权失败!"];
     }
+
 }
 
 - (void)showLog:(NSString *)log {
@@ -97,14 +99,11 @@ const NSString *instanceId = @"iot-040adh4x";
 }
 
 - (void)registerReuest{
-//    C0310000A58A   8228bd13d8ef4bed091a9f3d6c384b51
-//    C0310000A58A 62c5bfb84f79e387036c29a2e0ceef80
 
     NSMutableDictionary *params = [NSMutableDictionary dictionaryWithDictionary:@{
         @"Action":@"RegisterDevice",
         @"ProductKey":productKey,
         @"IotInstanceId":instanceId,
-//        @"DeviceName":@"C0310000A59C",
         @"DeviceName": self.deviceInfo.mac,
     }] ;
     params[@"Format"] = @"JSON";
index 79d7155..926899f 100644 (file)
Binary files a/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate and b/MouseSdk/MouseSdk.xcworkspace/xcuserdata/apple.xcuserdatad/UserInterfaceState.xcuserstate differ