当前位置:网站首页>融云获取Token
融云获取Token
2022-06-21 18:54:00 【EmulateStep】
#import "AppDelegate.h"
#import <RongIMKit/RongIMKit.h>
#import <AFNetworking.h>
#import <CommonCrypto/CommonDigest.h>// 加密
// 获取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]];
//以下拼接请求内容
[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"];
//开始请求
[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(@"%@", @"失败 ");
}];
}
// 加密
- (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;
}
边栏推荐
- Gartner 网络研讨会 “九问数字化转型” 会后感
- Visualization of operation and maintenance monitoring data - let the data speak [Huahui data]
- The highest monthly salary is 17k. As long as there is a field of hope in your heart, hard work will usher in a green land~
- Jenkins regularly builds and passes build parameters
- Quartus II 18.0软件安装包和安装教程
- 自然语言处理如何实现聊天机器人?
- Flink CDC MongoDB Connector 的实现原理和使用实践
- How to find the desired file among thousands of files on your computer?
- 细节、MYSQL_DATE_FORMAT()_函数_详解(记得收藏)
- Details, MySQL_ DATE_ FORMAT()_ Functions_ Detailed explanation (remember to collect)
猜你喜欢

【微信小程序】协同工作和发布 数据绑定

Implementation principle and application practice of Flink CDC mongodb connector

Pfsense configuring tinc site to site tunneling tutorial

The second round of layoffs in a large factory is coming, and the routine is full

Servlet使用

TX9118 同步升压IC

How to distinguish between machine learning and pattern recognition?

Delete the penultimate node - linked list topic

In May, I just came back from the Ali software testing post. I worked for Alibaba P7 at 3+1, with an annual salary of 28*15

Point cloud to depth map: conversion, saving, visualization
随机推荐
Category
break和continue的区别
mysql与oracle有没有区别
Anfulai embedded weekly report (issue 270): June 13, 2022 to June 19, 2022
同步升压 DC/DC 转换器FS3400同步SOT23-6小电流500MA升压ic
瀚高数据库自定义操作符'!~~'
开通融资融券账户安全吗?有什么要求?
Inno setup change installation path learning
Problems caused by redis caching scenario
机器学习和模式识别怎么区分?
数组的最小不可组成和问题
如何使用Memcached实现Django项目缓存
SD集训6.21总结
JVM memory structure
jmeter线程持续时间
Advanced algebra_ Chapter 9: linear mapping
起飞,年薪40万+
MySQL CentOS installation MySQL L8
国标设备注册EasyCVR平台,如何修改设备在离线状态判断的时间?
Jenkins regularly builds and passes build parameters