当前位置:网站首页>Rongyun obtains token
Rongyun obtains token
2022-06-21 20:39:00 【EmulateStep】
#import "AppDelegate.h"
#import <RongIMKit/RongIMKit.h>
#import <AFNetworking.h>
#import <CommonCrypto/CommonDigest.h>// encryption
// obtain token
- (void)getRCIMToken
{
AFHTTPSessionManager *manager = [AFHTTPSessionManagermanager];
// manager.requestSerializer = [AFJSONRequestSerializer serializer];
NSString *urlstr =@"https://api.cn.rong.io/user/getToken.json";
NSDictionary *dic =@{ @"userId":@"XK",
@"name":@"XKChat",
@"portraitUri":@"https://www.baidu.com/img/baidu_jgylogo3.gif"
};
NSString * timestamp = [[NSStringalloc] initWithFormat:@"%ld",(NSInteger)[NSDatetimeIntervalSinceReferenceDate]];
// NSDate *dateObc = [NSDate date];
// NSString *timestamp = [NSString stringWithFormat:@"%d",(int)[dateObc timeIntervalSince1970]];
NSString * nonce = [NSStringstringWithFormat:@"%d",arc4random()];
NSString * appkey = @"mgb7ka1nbz5cg";
NSString * Signature = [selfsha1:[NSStringstringWithFormat:@"%@%@%@",appkey,nonce,timestamp]];
// The following splicing request content
[manager.requestSerializersetValue:appkey forHTTPHeaderField:@"App-Key"];
[manager.requestSerializersetValue:nonce forHTTPHeaderField:@"Nonce"];
[manager.requestSerializersetValue:timestamp forHTTPHeaderField:@"Timestamp"];
[manager.requestSerializersetValue:Signature forHTTPHeaderField:@"Signature"];
[manager.requestSerializersetValue:@"x2KUyWY7WrldUc"forHTTPHeaderField:@"appSecret"];
[manager.requestSerializersetValue:@"application/x-www-form-urlencoded"forHTTPHeaderField:@"Content-Type"];
// To request
[manager POST:urlstr parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
NSLog(@"%@", responseObject);
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"%@", @" Failure ");
}];
}
// encryption
- (NSString *) sha1:(NSString *)input
{
NSData *data = [input dataUsingEncoding:NSUTF8StringEncoding];
uint8_t digest[CC_SHA1_DIGEST_LENGTH];
CC_SHA1(data.bytes, (unsignedint)data.length, digest);
NSMutableString *output = [NSMutableStringstringWithCapacity:CC_SHA1_DIGEST_LENGTH *2];
for(int i=0; i<CC_SHA1_DIGEST_LENGTH; i++) {
[output appendFormat:@"%02x", digest[i]];
}
return output;
}
边栏推荐
- Jenkins regularly builds and passes build parameters
- Whether there are keywords in MySQL
- Problems caused by redis caching scenario
- Simple integration of client go gin IX create
- Flutter AutomaticKeepAliveClientMixin缓存组件
- 运维监控数据可视化-让数据自己会说话[华汇数据]
- 模拟input输入并获得print输出的内容
- 【基于合泰HT32F52352的智慧垃圾桶总结】
- 点云转深度图:转化,保存,可视化
- Servlet usage
猜你喜欢
随机推荐
How to debug reorganization in jetpack compose
Alibaba cloud ack one and ACK cloud native AI suite have been newly released to meet the needs of the end of the computing era
Quartus II 18.0软件安装包和安装教程
Snake game project full version
點雲轉深度圖:轉化,保存,可視化
Implementation of assembly language greedy snake and Tetris dual task design (II) -- detailed design of greedy snake
运维监控数据可视化-让数据自己会说话[华汇数据]
FS9935 高效率恒流限流 WLED 驱动IC
client-go gin的简单整合九-Create
Can the financial product be redeemed on the due date?
高度可扩展,EMQX 5.0 达成 1 亿 MQTT 连接
阿里云 ACK One、ACK 云原生 AI 套件新发布,解决算力时代下场景化需求
How to query the maximum ID value in MySQL
Kubernetes-23:详解如何将CPU Manager做到游刃有余
Summary of methods for NSIS to run bat
现在CDC支持到MySQL5.几了?之前好像说是5.7,今天发现5.6的MySQL数据源也能实时更新
带你区分几种并行
浅析Js中${}字符串拼接
pfSense配置TINC站点至站点隧道教程
Henkel database custom operator '! ~~'









