Keine Beschreibung

FLShareHelper.m 4.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. //
  2. // FLShareHelper.m
  3. // FirstLink
  4. //
  5. // Created by unicode on 14-11-5.
  6. // Copyright (c) 2014年 FirstLink. All rights reserved.
  7. //
  8. #import "WXApi.h"
  9. #import "WeiboSDK.h"
  10. //#import <TencentOpenAPI/QQApi.h>
  11. #import <TencentOpenAPI/QQApiInterface.h>
  12. #import <TencentOpenAPI/QQApiInterfaceObject.h>
  13. #import "FLShareHelper.h"
  14. #import "OAuthManager.h"
  15. #import "FKTargetConfigUtil.h"
  16. @implementation FLShareHelper
  17. + (void)shareToWeixin:(NSString *)title
  18. description:(NSString *)description
  19. thumbImage:(UIImage *)image
  20. webURL:(NSString *)urlString
  21. scene:(WeixinScene)scene
  22. {
  23. if (title.length > TITLE_LENGTH) {
  24. title = [title substringToIndex:TITLE_LENGTH];
  25. }
  26. if (description.length > DESCRIPTION_LENGTH) {
  27. description = [description substringToIndex:DESCRIPTION_LENGTH];
  28. }
  29. WXMediaMessage *message = [WXMediaMessage message];
  30. message.title = title;
  31. message.description = description;
  32. [message setThumbImage:image];
  33. NSURL *url = [NSURL URLWithString:urlString];
  34. if (scene == WeixinSceneFriend) {
  35. urlString = [[NSString alloc] initWithFormat:@"%@%@%@", [url absoluteString],
  36. [url query] ? @"&" : @"?", @"p_r=PageH5WeixinFriend"];
  37. } else if (scene == WeixinSceneCicle) {
  38. urlString = [[NSString alloc] initWithFormat:@"%@%@%@", [url absoluteString],
  39. [url query] ? @"&" : @"?", @"p_r=PageH5WeixinCircle"];
  40. }
  41. WXWebpageObject *ext = [WXWebpageObject object];
  42. ext.webpageUrl = urlString;
  43. message.mediaObject = ext;
  44. SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];
  45. req.bText = NO;
  46. req.message = message;
  47. req.scene = scene;
  48. [WXApi sendReq:req];
  49. }
  50. + (void)shareToWeiboWithTitle:(NSString *)title
  51. content:(NSString *)content
  52. image:(UIImage *)image
  53. urlString:(NSString *)urlString
  54. tagID:(NSString *)tagID;
  55. {
  56. if (!image) return;
  57. WBMessageObject *wbMessage = [[WBMessageObject alloc]init];
  58. WBImageObject *imgObj = [[WBImageObject alloc]init];
  59. NSData *imageData = UIImagePNGRepresentation(image);
  60. if (!imageData){
  61. imageData = UIImageJPEGRepresentation(image, 0.5f);
  62. }
  63. imgObj.imageData = imageData;
  64. wbMessage.imageObject = imgObj;
  65. // text 长度小于140个汉字, url不算
  66. // WBWebpageObject *webObject = [WBWebpageObject object];
  67. // webObject.webpageUrl = urlString;
  68. // webObject.title = title;
  69. // webObject.description = content;
  70. // webObject.thumbnailData = imageData;
  71. // webObject.objectID = tagID;
  72. if (title.length > 50){
  73. title = [title substringToIndex:50];
  74. }
  75. NSURL *url = [NSURL URLWithString:urlString];
  76. urlString = [[NSString alloc] initWithFormat:@"%@%@%@", [url absoluteString],
  77. [url query] ? @"&" : @"?", @"p_r=PageH5Weibo"];
  78. wbMessage.text = [title stringByAppendingString:[NSString stringWithFormat:@" %@", urlString]];
  79. WBAuthorizeRequest *authReq = [WBAuthorizeRequest request];
  80. authReq.redirectURI = @"https://api.weibo.com/oauth2/default.html";
  81. authReq.scope = @"all";
  82. NSString *token = [OAuthManager sharedManager].weiboAuth.token;
  83. WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:wbMessage authInfo:authReq access_token:token];
  84. [WeiboSDK sendRequest:request];
  85. }
  86. + (void)shareToQQZoneWithTitle:(NSString *)title
  87. content:(NSString *)content
  88. imgUrl:(NSString *)imgUrl
  89. urlString:(NSString *)urlString
  90. {
  91. if (urlString.length == 0) return;
  92. if (content.length > 135) {
  93. content = [content substringToIndex:135];
  94. }
  95. NSURL *url = [NSURL URLWithString:urlString];
  96. urlString = [[NSString alloc] initWithFormat:@"%@%@%@", [url absoluteString],
  97. [url query] ? @"&" : @"?", @"p_r=PageH5QQZone"];
  98. QQApiNewsObject *newsObj= [QQApiNewsObject objectWithURL:[NSURL URLWithString:urlString]
  99. title:title
  100. description:content
  101. previewImageURL:[NSURL URLWithString:imgUrl]];
  102. SendMessageToQQReq *qqReq = [SendMessageToQQReq reqWithContent:newsObj];
  103. [QQApiInterface SendReqToQZone:qqReq];
  104. }
  105. + (UIImage *)getIconImg{
  106. return [UIImage imageNamed:@"Alpha3_SelectedIcon"];
  107. }
  108. + (NSString *)defaultShareDescription{
  109. return [NSString stringWithFormat:@"【%@】您的全球购物管家", [FKTargetConfigUtil appName]];
  110. }
  111. @end