Skip to content

Commit 5c30f77

Browse files
author
eagleychen
committed
添加iotexplore平台appkey/appsecret上报开关控制
1 parent 13bf4b2 commit 5c30f77

File tree

5 files changed

+132
-11
lines changed

5 files changed

+132
-11
lines changed

Podfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ target 'LinkApp' do
3030
pod 'CocoaAsyncSocket', '7.6.5'
3131
pod 'TIoTLinkKit_TPNS', '1.0.1'
3232
pod 'TIoTLinkKit_WechatOpenSDK', '1.0.1'
33-
pod 'TIoTLinkKit_IJKPlayer', '2.0.14'
33+
pod 'TIoTLinkKit_IJKPlayer', '2.0.15'
3434
pod 'Bugly', '2.5.91'
3535
end
3636

@@ -42,7 +42,7 @@ target 'LinkSDKDemo' do
4242
pod 'TIoTLinkKit/LinkRTC', :path => './'
4343

4444
pod 'TIoTLinkVideo', :path => './'
45-
pod 'TIoTLinkKit_IJKPlayer', '2.0.14'
45+
pod 'TIoTLinkKit_IJKPlayer', '2.0.15'
4646
end
4747

4848
#older OS versions does not contain 'libarclite', at least iOS 11

Podfile.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ PODS:
3131
- YYModel (= 1.0.4)
3232
- TIoTLinkKit_FLV (2.2.3)
3333
- TIoTLinkKit_GVoiceSE (1.0.9)
34-
- TIoTLinkKit_IJKPlayer (2.0.14)
34+
- TIoTLinkKit_IJKPlayer (2.0.15)
3535
- TIoTLinkKit_SoundTouch (1.0.0)
3636
- TIoTLinkKit_TPNS (1.0.1)
3737
- TIoTLinkKit_WechatOpenSDK (1.0.1)
@@ -66,7 +66,7 @@ DEPENDENCIES:
6666
- Tencent-MapSDK (= 4.3.9)
6767
- TIoTLinkKit (from `./`)
6868
- TIoTLinkKit/LinkRTC (from `./`)
69-
- TIoTLinkKit_IJKPlayer (= 2.0.14)
69+
- TIoTLinkKit_IJKPlayer (= 2.0.15)
7070
- TIoTLinkKit_TPNS (= 1.0.1)
7171
- TIoTLinkKit_WechatOpenSDK (= 1.0.1)
7272
- TIoTLinkVideo (from `./`)
@@ -129,7 +129,7 @@ SPEC CHECKSUMS:
129129
TIoTLinkKit: 0386fb583c61765a02ad5cca810c7661d5a0bc53
130130
TIoTLinkKit_FLV: aec2b2ec9664990ec6c5b9f760fc1a9043d5a9a5
131131
TIoTLinkKit_GVoiceSE: 27d0b2045a1acc600cd69c256e7667dacf7dc051
132-
TIoTLinkKit_IJKPlayer: 1e265522952144af73724a31d6c80ebc15571f59
132+
TIoTLinkKit_IJKPlayer: 55cc0faec1a9395118fe0309652e83b8136d0599
133133
TIoTLinkKit_SoundTouch: cf79ae182b6c2349ff65bac7a338974bc538fa77
134134
TIoTLinkKit_TPNS: 7cea4fc1d20ef6c4c11c4f0b66bbb10ecf4ed968
135135
TIoTLinkKit_WechatOpenSDK: 7822d68cc5c46edf3f6020422202e7b65ea87614
@@ -141,6 +141,6 @@ SPEC CHECKSUMS:
141141
TZImagePickerController: bf4c57b98d8707fce41ea6be872414a71c7a8c9d
142142
YYModel: 2a7fdd96aaa4b86a824e26d0c517de8928c04b30
143143

144-
PODFILE CHECKSUM: 42de8ca533c86096306219fc1fd5570192d78ed0
144+
PODFILE CHECKSUM: 795d3763c3242d732936fb2a6c17075ff99dd006
145145

146146
COCOAPODS: 1.14.3

Source/SDK/LinkVideo/TIoTCoreXP2PBridge.h

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ extern NSNotificationName const TIoTCoreXP2PBridgeNotificationDetectError;
1818
extern NSNotificationName const TIoTCoreXP2PBridgeNotificationDeviceMsg;
1919
extern NSNotificationName const TIoTCoreXP2PBridgeNotificationStreamEnd;
2020

21+
@interface TIoTP2PAPPConfig : NSObject
22+
@property (nonatomic, strong)NSString *appkey; //为explorer平台注册的应用信息(https://console.cloud.tencent.com/iotexplorer/v2/instance/app/detai) explorer控制台- 应用开发 - 选对应的应用下的 appkey/appsecret
23+
@property (nonatomic, strong)NSString *appsecret; //为explorer平台注册的应用信息(https://console.cloud.tencent.com/iotexplorer/v2/instance/app/detai)
24+
@property (nonatomic, strong)NSString *userid; //用户纬度(每个手机区分开)使用用户自有的账号系统userid;若无请配置为[TIoTCoreXP2PBridge sharedInstance].getAppUUID; 查找日志是需提供此userid字段
25+
@end
26+
2127
@protocol TIoTCoreXP2PBridgeDelegate <NSObject>
2228

2329
/*
@@ -84,7 +90,8 @@ extern NSNotificationName const TIoTCoreXP2PBridgeNotificationStreamEnd;
8490
* 此接口只二者选一:传入xp2pinfo 就不需要填写 secretid和secretkey,xp2pinfo可从自建服务获取;
8591
* 仅跑通流程的话,可设置 secretid和secretkey 两个参数,xp2pinfo传“”即可
8692
*/
87-
- (XP2PErrCode)setXp2pInfo:(NSString *)dev_name sec_id:(NSString *)sec_id sec_key:(NSString *)sec_key xp2pinfo:(NSString *)xp2pinfo;
93+
- (XP2PErrCode)setXp2pInfo:(NSString *)dev_name sec_id:(NSString *)sec_id sec_key:(NSString *)sec_key xp2pinfo:(NSString *)xp2pinfo __attribute__((deprecated("Use -setXp2pInfo: xp2pinfo:")));
94+
- (XP2PErrCode)setXp2pInfo:(NSString *)dev_name xp2pinfo:(NSString *)xp2pinfo appconfig:(TIoTP2PAPPConfig *)appconfig;
8895

8996
/*
9097
* 使用播放器播放时,需先等待 SDK 初始化完成,ready事件(xp2preconnect 通知)之后,即可获取到 http-url

Source/SDK/LinkVideo/TIoTCoreXP2PBridge.mm

Lines changed: 111 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
#import "TIoTCoreXP2PBridge.h"
88
#import "TIoTCoreLogger.h"
99
#include <string.h>
10+
#include <CommonCrypto/CommonDigest.h>
11+
#include <CommonCrypto/CommonHMAC.h>
1012

1113
NSNotificationName const TIoTCoreXP2PBridgeNotificationDisconnect = @"xp2disconnect"; //p2p通道断开
1214
NSNotificationName const TIoTCoreXP2PBridgeNotificationReady = @"xp2preconnect"; //app本地已ready,表示探测完成,可以发起请求了
@@ -16,6 +18,10 @@
1618

1719
FILE *p2pOutLogFile;
1820
//NSFileHandle *fileHandle;
21+
static BOOL p2p_log_enabled = NO;
22+
static BOOL ops_report_enabled = NO;
23+
@implementation TIoTP2PAPPConfig
24+
@end
1925

2026
@interface TIoTCoreXP2PBridge ()<TIoTAVCaptionFLVDelegate>
2127
@property (nonatomic, strong) NSString *dev_name;
@@ -38,8 +44,8 @@ - (void)doTick:(data_report_t)data_buf;
3844
}
3945

4046
if (type == XP2PTypeLog) {
41-
if (logEnable) {
42-
fwrite(msg, 1, strlen(msg)>300?300:strlen(msg), p2pOutLogFile);
47+
if (p2p_log_enabled) {
48+
// fwrite(msg, 1, strlen(msg)>300?300:strlen(msg), p2pOutLogFile);
4349
[[TIoTCoreXP2PBridge sharedInstance].logger addLog:[NSString stringWithCString:msg encoding:NSASCIIStringEncoding]];
4450
}
4551
return nullptr;
@@ -219,6 +225,8 @@ - (instancetype)init {
219225
p2pOutLogFile = fopen(logFile.UTF8String, "wb");
220226

221227
_uniReqStartTime = [NSMutableDictionary dictionary];
228+
229+
[self getAppConfig];
222230
}
223231
return self;
224232
}
@@ -288,11 +296,92 @@ - (XP2PErrCode)setXp2pInfo:(NSString *)dev_name sec_id:(NSString *)sec_id sec_ke
288296
}
289297
setQcloudApiCred([sec_id UTF8String], [sec_key UTF8String]); //正式版app发布时候不需要传入secretid和secretkey,避免泄露secretid和secretkey,此处仅为演示
290298
}
299+
300+
TIoTP2PAPPConfig *config = [TIoTP2PAPPConfig new];
301+
config.appkey = @"appkey"; //为explorer平台注册的应用信息(https://console.cloud.tencent.com/iotexplorer/v2/instance/app/detai) explorer控制台- 应用开发 - 选对应的应用下的 appkey/appsecret
302+
config.appsecret = @"appsecret"; //为explorer平台注册的应用信息(https://console.cloud.tencent.com/iotexplorer/v2/instance/app/detai) explorer控制台- 应用开发 - 选对应的应用下的 appkey/appsecret
303+
config.userid = [self getAppUUID];
304+
[self setXp2pInfo:dev_name xp2pinfo:xp2pinfo appconfig:config];
305+
return XP2P_ERR_INIT_PRM;
306+
}
291307

308+
- (XP2PErrCode)setXp2pInfo:(NSString *)dev_name xp2pinfo:(NSString *)xp2pinfo appconfig:(TIoTP2PAPPConfig *)appconfig {
309+
if (!appconfig || appconfig.appkey.length < 1 || appconfig.appsecret.length < 1 || appconfig.userid.length < 1) {
310+
NSLog(@"请输入正确的appconfig");
311+
return XP2P_ERR_INIT_PRM;
312+
}
313+
if (xp2pinfo == nil || xp2pinfo.length < 1) {
314+
NSLog(@"请输入正确的xp2pInfo");
315+
return XP2P_ERR_INIT_PRM;
316+
}
317+
[self appGetUserConfig:appconfig];
292318
int ret = setDeviceXp2pInfo(dev_name.UTF8String, xp2pinfo.UTF8String);
293319
return (XP2PErrCode)ret;
294320
}
295321

322+
NSString *createSortedQueryString(NSMutableDictionary *params) {
323+
NSArray *sortedKeys = [[params allKeys] sortedArrayUsingSelector:@selector(compare:)];
324+
NSMutableArray *keyValuePairs = [NSMutableArray array];
325+
for (NSString *key in sortedKeys) {
326+
NSString *value = [params objectForKey:key];
327+
NSString *keyValuePair = [NSString stringWithFormat:@"%@=%@", key, value];
328+
[keyValuePairs addObject:keyValuePair];
329+
}
330+
NSString *queryString = [keyValuePairs componentsJoinedByString:@"&"];
331+
return queryString;
332+
}
333+
- (NSString *)signMessage:(NSString *)message withSecret:(NSString *)secret {
334+
@try {
335+
// Base64 解码
336+
const char *cKey = [secret cStringUsingEncoding:NSASCIIStringEncoding];
337+
const char *cData = [message cStringUsingEncoding:NSASCIIStringEncoding];
338+
339+
//sha1
340+
unsigned char cHMAC[CC_SHA1_DIGEST_LENGTH];
341+
CCHmac(kCCHmacAlgSHA1, cKey, strlen(cKey), cData, strlen(cData), cHMAC);
342+
343+
NSData *HMAC = [[NSData alloc] initWithBytes:cHMAC length:sizeof(cHMAC)];
344+
345+
NSString *hash = [HMAC base64EncodedStringWithOptions:0];//将加密结果进行一次BASE64编码。
346+
return hash;
347+
} @catch (NSException *exception) {
348+
NSLog(@"签名错误:%@", exception);
349+
}
350+
return nil;
351+
}
352+
353+
- (void)appGetUserConfig:(TIoTP2PAPPConfig *)appconfig {
354+
NSMutableDictionary *accessParam = [NSMutableDictionary dictionary];
355+
[accessParam setValue:@"AppDescribeLogLevel" forKey:@"Action"];
356+
[accessParam setValue:@([[TIoTCoreXP2PBridge getNowTimeTimestampSec] integerValue]) forKey:@"Timestamp"];
357+
[accessParam setValue:@(arc4random()) forKey:@"Nonce"];
358+
[accessParam setValue:appconfig.appkey forKey:@"AppKey"];
359+
[accessParam setValue:appconfig.userid forKey:@"UserId"];
360+
[accessParam setValue:[[NSUUID UUID] UUIDString] forKey:@"RequestId"];
361+
362+
NSString *content = createSortedQueryString(accessParam);
363+
NSString *signature = [self signMessage:content withSecret:appconfig.appsecret];
364+
[accessParam setValue:signature forKey:@"Signature"];
365+
366+
367+
NSURL *url = [NSURL URLWithString:@"http://localhost:80/appapiv1"];
368+
NSMutableURLRequest *reqlog = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:5];
369+
[reqlog setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
370+
reqlog.HTTPMethod = @"POST";
371+
reqlog.HTTPBody = [NSJSONSerialization dataWithJSONObject:accessParam options:NSJSONWritingFragmentsAllowed error:nil];;
372+
NSURLSessionDataTask *tasklog = [[NSURLSession sharedSession] dataTaskWithRequest:reqlog completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
373+
374+
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *)response;
375+
if (httpResponse.statusCode == 200) {
376+
NSError *jsonerror = nil;
377+
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&jsonerror];
378+
// NSLog(@"log serverapi:content===>%@, param==>%@, data===>%@",content,accessParam,dic);
379+
[self setAppConfig:[[dic objectForKey:@"Response"] objectForKey:@"Data"]];
380+
}
381+
}];
382+
[tasklog resume];
383+
}
384+
296385
- (NSString *)getUrlForHttpFlv:(NSString *)dev_name {
297386
const char *httpflv = delegateHttpFlv(dev_name.UTF8String);
298387
NSLog(@"httpflv---%s",httpflv);
@@ -647,7 +736,9 @@ - (void)doTick:(data_report_t)data_buf {
647736
}
648737

649738
- (void)reportUserList:(data_report_t)report {
650-
739+
if (!ops_report_enabled) {
740+
return;
741+
}
651742
NSString *reqid = [NSString stringWithCString:(const char *)report.uniqueId encoding:NSASCIIStringEncoding];
652743
NSString *status = [NSString stringWithCString:(const char *)report.status encoding:NSASCIIStringEncoding];
653744
NSString *dataaction = [NSString stringWithCString:(const char *)report.data_action encoding:NSASCIIStringEncoding];
@@ -696,6 +787,18 @@ - (void)reportUserList:(data_report_t)report {
696787
}
697788
}
698789

790+
- (void)getAppConfig {
791+
p2p_log_enabled = [self readKeychainValue:@"p2p_log_enabled"].boolValue;
792+
ops_report_enabled = [self readKeychainValue:@"ops_report_enabled"].boolValue;
793+
}
794+
- (void)setAppConfig:(NSDictionary *)appconfig {
795+
NSString * tmp_p2p_log_enabled = [appconfig objectForKey:@"P2PLogEnabled"];
796+
NSString * tmp_ops_report_enabled = [appconfig objectForKey:@"OpsLogEnabled"];
797+
798+
[self saveKeychainValue:tmp_p2p_log_enabled key:@"p2p_log_enabled"];
799+
[self saveKeychainValue:tmp_ops_report_enabled key:@"ops_report_enabled"];
800+
}
801+
699802
+ (NSString *)getSDKVersion {
700803
return [NSString stringWithUTF8String:VIDEOSDKVERSION];
701804
}
@@ -713,5 +816,9 @@ +(NSString *)getNowTimeTimestamp {
713816
NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)([datenow timeIntervalSince1970]*1000)];
714817
return timeSp;
715818
}
716-
819+
+(NSString *)getNowTimeTimestampSec {
820+
NSDate *datenow = [NSDate date];
821+
NSString *timeSp = [NSString stringWithFormat:@"%ld", (long)[datenow timeIntervalSince1970]];
822+
return timeSp;
823+
}
717824
@end

TIoTLinkKit.xcodeproj/xcshareddata/xcschemes/LinkSDKDemo.xcscheme

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@
5151
ReferencedContainer = "container:TIoTLinkKit.xcodeproj">
5252
</BuildableReference>
5353
</BuildableProductRunnable>
54+
<EnvironmentVariables>
55+
<EnvironmentVariable
56+
key = "OS_ACTIVITY_MODE"
57+
value = "disable"
58+
isEnabled = "NO">
59+
</EnvironmentVariable>
60+
</EnvironmentVariables>
5461
</LaunchAction>
5562
<ProfileAction
5663
buildConfiguration = "Release"

0 commit comments

Comments
 (0)