123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- //
- // FLShareHelper.m
- // FirstLink
- //
- // Created by unicode on 14-11-5.
- // Copyright (c) 2014年 FirstLink. All rights reserved.
- //
- #import "WXApi.h"
- #import "WeiboSDK.h"
- //#import <TencentOpenAPI/QQApi.h>
- #import <TencentOpenAPI/QQApiInterface.h>
- #import <TencentOpenAPI/QQApiInterfaceObject.h>
- #import "FLShareHelper.h"
- #import "OAuthManager.h"
- #import "FKTargetConfigUtil.h"
- @implementation FLShareHelper
- + (void)shareToWeixin:(NSString *)title
- description:(NSString *)description
- thumbImage:(UIImage *)image
- webURL:(NSString *)urlString
- scene:(WeixinScene)scene
- {
- if (title.length > TITLE_LENGTH) {
- title = [title substringToIndex:TITLE_LENGTH];
- }
- if (description.length > DESCRIPTION_LENGTH) {
- description = [description substringToIndex:DESCRIPTION_LENGTH];
- }
-
- WXMediaMessage *message = [WXMediaMessage message];
- message.title = title;
- message.description = description;
- [message setThumbImage:image];
-
- NSURL *url = [NSURL URLWithString:urlString];
- if (scene == WeixinSceneFriend) {
- urlString = [[NSString alloc] initWithFormat:@"%@%@%@", [url absoluteString],
- [url query] ? @"&" : @"?", @"p_r=PageH5WeixinFriend"];
- } else if (scene == WeixinSceneCicle) {
- urlString = [[NSString alloc] initWithFormat:@"%@%@%@", [url absoluteString],
- [url query] ? @"&" : @"?", @"p_r=PageH5WeixinCircle"];
- }
-
- WXWebpageObject *ext = [WXWebpageObject object];
- ext.webpageUrl = urlString;
-
- message.mediaObject = ext;
-
- SendMessageToWXReq* req = [[SendMessageToWXReq alloc] init];
- req.bText = NO;
- req.message = message;
- req.scene = scene;
-
- [WXApi sendReq:req];
- }
- + (void)shareToWeiboWithTitle:(NSString *)title
- content:(NSString *)content
- image:(UIImage *)image
- urlString:(NSString *)urlString
- tagID:(NSString *)tagID;
- {
- if (!image) return;
- WBMessageObject *wbMessage = [[WBMessageObject alloc]init];
- WBImageObject *imgObj = [[WBImageObject alloc]init];
- NSData *imageData = UIImagePNGRepresentation(image);
- if (!imageData){
- imageData = UIImageJPEGRepresentation(image, 0.5f);
- }
- imgObj.imageData = imageData;
- wbMessage.imageObject = imgObj;
- // text 长度小于140个汉字, url不算
-
- // WBWebpageObject *webObject = [WBWebpageObject object];
- // webObject.webpageUrl = urlString;
- // webObject.title = title;
- // webObject.description = content;
- // webObject.thumbnailData = imageData;
- // webObject.objectID = tagID;
-
- if (title.length > 50){
- title = [title substringToIndex:50];
- }
-
- NSURL *url = [NSURL URLWithString:urlString];
- urlString = [[NSString alloc] initWithFormat:@"%@%@%@", [url absoluteString],
- [url query] ? @"&" : @"?", @"p_r=PageH5Weibo"];
-
- wbMessage.text = [title stringByAppendingString:[NSString stringWithFormat:@" %@", urlString]];
-
- WBAuthorizeRequest *authReq = [WBAuthorizeRequest request];
- authReq.redirectURI = @"https://api.weibo.com/oauth2/default.html";
- authReq.scope = @"all";
-
- NSString *token = [OAuthManager sharedManager].weiboAuth.token;
- WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:wbMessage authInfo:authReq access_token:token];
- [WeiboSDK sendRequest:request];
-
- }
- + (void)shareToQQZoneWithTitle:(NSString *)title
- content:(NSString *)content
- imgUrl:(NSString *)imgUrl
- urlString:(NSString *)urlString
- {
- if (urlString.length == 0) return;
-
- if (content.length > 135) {
- content = [content substringToIndex:135];
- }
-
- NSURL *url = [NSURL URLWithString:urlString];
- urlString = [[NSString alloc] initWithFormat:@"%@%@%@", [url absoluteString],
- [url query] ? @"&" : @"?", @"p_r=PageH5QQZone"];
-
- QQApiNewsObject *newsObj= [QQApiNewsObject objectWithURL:[NSURL URLWithString:urlString]
- title:title
- description:content
- previewImageURL:[NSURL URLWithString:imgUrl]];
-
- SendMessageToQQReq *qqReq = [SendMessageToQQReq reqWithContent:newsObj];
- [QQApiInterface SendReqToQZone:qqReq];
- }
- + (UIImage *)getIconImg{
- return [UIImage imageNamed:@"Alpha3_SelectedIcon"];
- }
- + (NSString *)defaultShareDescription{
- return [NSString stringWithFormat:@"【%@】您的全球购物管家", [FKTargetConfigUtil appName]];
- }
- @end
|