Skip to content

Commit

Permalink
add live comment send
Browse files Browse the repository at this point in the history
  • Loading branch information
typcn committed May 14, 2015
1 parent 85a2b09 commit 0ca4b2c
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions bilibili/PostComment.m
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ - (IBAction)Send:(id)sender {


NSURL* URL = [NSURL URLWithString:[NSString stringWithFormat:@"http://interface.bilibili.com/dmpost?cid=%@&aid=%@&pid=%@",vCID,vAID,vPID]];
if([vAID isEqualToString:@"LIVE"]){
URL = [NSURL URLWithString:@"http://live.bilibili.com/msg/send"];
}

NSMutableURLRequest* request = [NSMutableURLRequest requestWithURL:URL];
request.HTTPMethod = @"POST";
request.timeoutInterval = 5;
Expand All @@ -67,6 +71,17 @@ - (IBAction)Send:(id)sender {
@"message": text,
@"playTime": playTime,
};

if([vAID isEqualToString:@"LIVE"]){
bodyParameters = @{
@"roomid": vCID,
@"color": @"16777215",
@"mode": @"1",
@"fontsize": @"25",
@"msg": text,
};
}

request.HTTPBody = [NSStringFromQueryParameters(bodyParameters) dataUsingEncoding:NSUTF8StringEncoding];

// Headers
Expand All @@ -75,9 +90,13 @@ - (IBAction)Send:(id)sender {
[request addValue:userAgent forHTTPHeaderField:@"User-Agent"];
[request setValue:@"http://static.hdslb.com" forHTTPHeaderField:@"Origin"];
[request setValue:@"http://static.hdslb.com/play.swf" forHTTPHeaderField:@"Referer"];
[request setValue:@"ShockwaveFlash/17.0.0.134" forHTTPHeaderField:@"X-Requested-With"];
[request setValue:@"ShockwaveFlash/17.0.0.188" forHTTPHeaderField:@"X-Requested-With"];
// Cookies will add automatically

if([vAID isEqualToString:@"LIVE"]){
[request setValue:@"http://static.hdslb.com/live-static/swf/LivePlayerEx_1.swf" forHTTPHeaderField:@"Referer"];
}

// Send Request

NSURLResponse * response = nil;
Expand All @@ -89,7 +108,7 @@ - (IBAction)Send:(id)sender {

if([returnData length] > 0){
int x = [returnData intValue];
if (x > 0){
if (x > -1){
[sender setStringValue:@"😁发送成功!"];
NSLog(@"Comment sent. ID: %d",x);
}else{
Expand Down

0 comments on commit 0ca4b2c

Please sign in to comment.