美文网首页
普元微博分享示例

普元微博分享示例

作者: 红凉梦 | 来源:发表于2020-01-13 10:13 被阅读0次

2020.3.3 修改 微博分享 oc--js--未提交

微博分享,以及MTA统计

Method Parameter Description Return 示例
shareWeibochat(data,function(retCode,retMsg) //image、text、webUrl可以允许单项为空,图片、文字、与多媒体不能组合分享
var data = {
"image" : {"imagePath" : "/images/app.png"} ,
"text" :{ "text" : "我要分享的内容是2月14日情人节" } ,
"webUrl" : { "actionUrl" : "https://weibo.com",
"defaultText" : "默认网页",
"description" : "描述文字",
"thumbData" : "/images/app.png",
"title" : "测试网页"
}
}
微博分享 Utils.shareWeibochat(data,function(retCode,retMsg){
log(retCode+','+retMsg);
});
Utils.beginLoadPage('xxxx.html'); 2 开始进入界面 3 $M.page.addEvent('onLoad', function(param{
Utils.beginLoadPage('index.html');
});
Utils.endLoadPage('xxx.html'); 2 离开界面时使用,与开始结合使用,否则无效 3 Utils.endLoadPage('xxx.html');
$M.page.goTo('/xxx.htmlx', null, false);
Utils.eventIDClick(eventid,lableType); @param event_id 事件的ID,ID需要先在MTA前台配置好才能生效
lableType:事件类型
统计点击事件 function share(){Utils.eventIDClick("share","shareType");}
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>new title</title>
</head>
<body>
<nav title="测试分享"/>
<div  width="100%" >
<input type="label" value="分享到" />
<select id="select" value="session" width="100%" >
  <option text="会话" value="session" ></option>
  <option text="朋友圈" value="timeline" ></option>
  <option text="收藏" value="favorite" ></option>
</select>
  </div>
  <input type="button"  value="分享微博" onClick="shareWeibo" width="100%"/>
  
  </body>
  <script>
  $M.page.addEvent('onLoad', function(param){
        Utils.beginLoadPage('index.html');
  });

    function shareWeibo(){
        var data = {
            "image" :"" /* {
                    "imagePath" : "/images/app.png"
                     } */,
            "text" :"" /* {
                    "text" : "我要分享的内容是2月14日情人节"
                     } */,
             "webUrl" : {
                     "actionUrl" : "https://weibo.com",
                    "defaultText" : "默认网页",
                    "description" : "描述文字",
                    "thumbData" : "/images/app.png",
                    "title" : "测试网页"
                    } 
            }
    
        Utils.shareWeibochat(data,function(retCode,retMsg){
            log(retCode+','+retMsg);
        });
    }

  
 
  </script>
  </html>

OC端

//
//  SkyShareWeiboSdk.m
//  EmpBridge
//
//  Created by GuoYanjun on 2019/12/30.
//  Copyright © 2019 LiuLei. All rights reserved.
//

#import "SkyShareWeiboSdk.h"
#import "SkyDataRef.h"
#import "SKY_FileUrl.h"
#import "ResourceManager.h"
#import "SKY_Image.h"
@implementation SkyShareWeiboSdk
-(instancetype)init{
    if (self =[super init]) {
        [SkyWeiboManager sharedManager].delegate = self;
    }
    return self;
}

-(SkyDataRef *)messageShare:(NSDictionary *)param{
    SkyWeiboManager *mydele=[[SkyWeiboManager alloc]init];
    WBAuthorizeRequest *authRequest = [WBAuthorizeRequest request];
    authRequest.redirectURI = @"https://api.weibo.com/oauth2/default.html";
    authRequest.scope = @"all";
    
    
    WBMessageObject *message = [WBMessageObject message];
    if ([param stringValue:@"image"] && ![[param stringValue:@"image"] isKindOfClass:[NSNull class]] && [param stringValue:@"image"].length >0){
        NSDictionary *imageDic =param[@"image"];
        NSString *imagePath =[imageDic stringValue:@"imagePath"];
                NSString *resUrl1 = [[ResourceManager instance] getResourcePathFormRes:imagePath];
        UIImage * thumbImage = nil;
        UIImage *originalImage = nil;
        originalImage = [SKY_FileUrl imageWithUrl:resUrl1];
        thumbImage = [SKY_Image compressImage:originalImage withScale:100];
        NSData * imageData = [NSData dataWithContentsOfFile:[SKY_FileUrl getRealPath:resUrl1]];
        WBImageObject *wbImg = [[WBImageObject alloc] init];
        wbImg.imageData =imageData;
        message.imageObject = wbImg;
    }
    if ([param stringValue:@"text"] && ![[param stringValue:@"text"] isKindOfClass:[NSNull class]] && [param stringValue:@"text"].length >0){
        NSDictionary *textDic =param[@"text"];
        NSString *text =[textDic stringValue:@"text"];
        message.text =text;
    }

    if ([param stringValue:@"webUrl"] && ![[param stringValue:@"webUrl"] isKindOfClass:[NSNull class]] && [param stringValue:@"webUrl"].length >0){
        NSDictionary *webUrlDic = param[@"webUrl"];
        NSString *title = [webUrlDic stringValue:@"title"];
        NSString *defaultText = [webUrlDic stringValue:@"defaultText"];
        NSString *description = [webUrlDic stringValue:@"description"];
        NSString *thumbData = [webUrlDic stringValue:@"thumbData"];
        NSString *actionUrl = [webUrlDic stringValue:@"actionUrl"];

       NSString *resUrl1 = [[ResourceManager instance] getResourcePathFormRes:thumbData];
       UIImage * thumbImage = nil;
       UIImage *originalImage = nil;
       originalImage = [SKY_FileUrl imageWithUrl:resUrl1];
       thumbImage = [SKY_Image compressImage:originalImage withScale:100];
        message.text = [NSString stringWithFormat:@"%@ %@ %@",NSLocalizedString(description, nil),actionUrl,NSLocalizedString(title, nil)];
        WBImageObject *imageOb = [WBImageObject object];
        imageOb.imageData =UIImagePNGRepresentation(thumbImage);
        message.imageObject = imageOb;
    }


    WBSendMessageToWeiboRequest *request = [WBSendMessageToWeiboRequest requestWithMessage:message authInfo:authRequest access_token:mydele.wbtoken];
    [WeiboSDK sendRequest:request];
    return successObjToDataRef(NULL);
}

- (void)managerDidRecvGetMessageReq:(WBSendMessageToWeiboResponse *)response{
    
     if (response.statusCode == WeiboSDKResponseStatusCodeSuccess) {
            //NSLog(@"微博----分享成功!!!");
             [self triggerEvent:@"ShareSuccess",intToDataRef(0),stringToDataRef(@"分享成功"),Nil];
     }else if(response.statusCode == WeiboSDKResponseStatusCodeUserCancel)
         {
     //        NSLog(@"微博----用户取消发送");
            [self triggerEvent:@"ShareSuccess",intToDataRef(-1),stringToDataRef(@"取消分享"),Nil];
         }else if (response.statusCode == WeiboSDKResponseStatusCodeSentFail){
     //        NSLog(@"微博----发送失败!");
            [self triggerEvent:@"ShareSuccess",intToDataRef(-2),stringToDataRef(@"发送失败"),Nil];
         }
}

@end

相关文章

  • 普元微博分享示例

    2020.3.3 修改 微博分享 oc--js--未提交 微博分享,以及MTA统计 MethodParameter...

  • 晨阳

    金辉普万象 心净沐浴阳 校准激快充 马嘶剑走光 ——新字第372篇 微信:flyfreeww 微博:驭元

  • 羽翔晨光

    煦阳普世享 清梦蛰晨光 不知天在水 啄羽尽翱翔 ——新字第387篇 微信:flyfreeww 微博:驭元

  • 2018-12-11

    夜辞贞素颜 晶絮悠漫天 鸿瑞普世煦 围炉话温祥 ——新字第331篇 微信:flyfreeww 微博:驭元

  • 创建类似新浪微博发表时间显示的转换的类方法

    新浪微博的微博内容显示的发表时间如示例图1所示,从服务器获取到的微博发表时间数据其实是如示例图2所示,这时就需要对...

  • 测试

    7. 流程图 示例 $E=mc^2$ 9. 表格支持 示例: 即显示微博的图标:

  • 2019年貔貅计划,尽我所能去省钱!

    01 之前经常在微博看到极简博主们分享“**元过一周”、“**元过一个月”之类的生活尝试,主要目的是减少购物欲。博...

  • 分享微博

    1*[cp]你脸上的云淡风轻, 谁也不知道你的牙咬的有多紧。 你笑的没心没肺, 没人知道你哭起来只能无声落泪。[悲...

  • 微博分享

    [cp]“女生要修炼成的五样东西: 扬在脸上的自信 长在心底的善良 融进血里的骨气 刻进命里的坚强 深到骨子里的教...

  • 微博分享

    [cp]“如果一个人说喜欢你,请等到他对你百般照顾时再相信,如果他答应带你去的地方,等他订好机票再开心,如果他说要...

网友评论

      本文标题:普元微博分享示例

      本文链接:https://www.haomeiwen.com/subject/qojgactx.html