分享房间和h5分享

This commit is contained in:
fengshuo
2021-11-24 14:31:24 +08:00
committed by zu
parent 463175f4f4
commit 02a0c55815
6 changed files with 152 additions and 28 deletions

View File

@@ -10,9 +10,11 @@
NS_ASSUME_NONNULL_BEGIN
typedef NS_ENUM(NSUInteger, ShareType) {
///分享房间
ShareType_Room,
ShareType_Room = 1,
///分享h5
ShareType_H5,
ShareType_H5 = 2,
///大转盘 目前没用到
ShareType_User_Draw = 888,
};
@interface XPShareInfoModel : NSObject
@@ -28,6 +30,10 @@ typedef NS_ENUM(NSUInteger, ShareType) {
@property (nonatomic,copy) UIImage *shareImage;
///分享的类型
@property (nonatomic,assign) ShareType type;
///分享类型1微信好友2微信朋友圈3QQ好友4QQ空间
@property (nonatomic,assign) NSInteger shareType;
///分享房间的uid
@property (nonatomic,assign) NSInteger roomUid;
@end

View File

@@ -10,11 +10,16 @@
NS_ASSUME_NONNULL_BEGIN
typedef enum : NSUInteger {
XPShareItemTagAppFriends, //应用好友
XPShareItemTagWeChat, //微信好友
XPShareItemTagMoments, //微信朋友圈
XPShareItemTagQQ, //QQ好友
XPShareItemTagQQZone, //QQ空间
///微信好友
XPShareItemTagWeChat = 1,
///微信朋友圈
XPShareItemTagMoments,
///QQ好友
XPShareItemTagQQ,
///QQ空间
XPShareItemTagQQZone,
///应用好友
XPShareItemTagAppFriends,
} XPShareItemTag;
@interface XPShareItem : NSObject

View File

@@ -15,7 +15,7 @@
///点了取消分享
- (void)shareViewDidClickCancel:(XPShareView *)shareView;
///分享成功
- (void)shareViewDidSuccess:(XPShareView *)shareView;
- (void)shareView:(XPShareView *)shareView didSuccess:(XPShareInfoModel *)shareInfo;
///分享失败
- (void)shareView:(XPShareView *)shareView shareFail:(NSString *)message;
@end;

View File

@@ -117,6 +117,7 @@
- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath{
[collectionView deselectItemAtIndexPath:indexPath animated:YES];
XPShareItem * item = [self.items objectAtIndex:indexPath.item];
self.shareInfo.shareType = item.type;
NSMutableDictionary *shareParams = [NSMutableDictionary dictionary];
NSString * title = [self.shareInfo shareTitle].length > 0 ? self.shareInfo.shareTitle : @"";
NSString * content = self.shareInfo.shareContent.length > 0 ? self.shareInfo.shareContent : @"";
@@ -132,8 +133,8 @@
switch (state) {
case SSDKResponseStateSuccess:
{
if (self.delegate && [self.delegate respondsToSelector:@selector(shareViewDidSuccess:)]) {
[self.delegate shareViewDidSuccess:self];
if (self.delegate && [self.delegate respondsToSelector:@selector(shareView:didSuccess:)]) {
[self.delegate shareView:self didSuccess:self.shareInfo];
}
}
break;
@@ -159,8 +160,8 @@
#pragma mark - Event Response
- (void)cancleButtonDidClck:(UIButton *)button{
if (self.delegate && [self.delegate respondsToSelector:@selector(shareViewDidSuccess:)]) {
[self.delegate shareViewDidSuccess:self];
if (self.delegate && [self.delegate respondsToSelector:@selector(shareViewDidClickCancel:)]) {
[self.delegate shareViewDidClickCancel:self];
}
}

View File

@@ -22,6 +22,7 @@
#import "ApiHost.h"
#import "AccountInfoStorage.h"
#import "IMMessageHelper.h"
#import "HttpRequestHelper.h"
///Model
#import "RoomInfoModel.h"
#import "UserInfoModel.h"
@@ -177,6 +178,8 @@
shareInfo.shareTitle = @"玩和平精英赢奖金";
shareInfo.shareContent = @"免费报名,奖金高,比赛多";
shareInfo.shareImageUrl = [self.hostDelegate getRoomInfo].avatar;
shareInfo.type = ShareType_Room;
shareInfo.roomUid = roomInfo.uid;
NSString * uid = [AccountInfoStorage instance].getUid;
NSString * urlString = [NSString stringWithFormat:@"%@/%@?shareUid=%@&uid=%ld&room_name=%@&room_id=%ld&room_avatar=%@&share_name=%@",API_HOST_URL,URLWithType(kShareRoomURL),uid,roomInfo.uid,roomInfo.title,roomInfo.erbanNo,roomInfo.avatar,roomInfo.nick];
shareInfo.shareUrl = urlString;
@@ -187,13 +190,35 @@
[TTPopup popupView:shareView style:TTPopupStyleActionSheet];
}
///
- (void)saveShare:(XPShareInfoModel *)shareInfo {
NSMutableDictionary *params = [NSMutableDictionary dictionary];
NSString *uid = [AccountInfoStorage instance].getUid;
NSString *ticket = [AccountInfoStorage instance].getTicket;
[params setObject:uid forKey:@"uid"];
[params setObject:@(shareInfo.shareType) forKey:@"shareType"];
[params setObject:ticket forKey:@"ticket"];
[params setObject:@(shareInfo.type) forKey:@"sharePageId"];
if (shareInfo.shareUrl.length > 0) {
[params setObject:shareInfo.shareUrl forKey:@"shareUrl"];
}
if (shareInfo.roomUid > 0) {
[params setObject:@(shareInfo.roomUid) forKey:@"targetUid"];
}
[HttpRequestHelper POST:@"usershare/save" params:params success:^(BaseModel * _Nonnull data) {
} failure:^(NSInteger resCode, NSString * _Nonnull message) {
}];
}
#pragma mark - XCShareViewDelegate
- (void)shareView:(XPShareView *)shareView shareFail:(NSString *)message {
[TTPopup dismiss];
[XCHUDTool showErrorWithMessage:message];
}
- (void)shareViewDidSuccess:(XPShareView *)shareView {
- (void)shareView:(XPShareView *)shareView didSuccess:(XPShareInfoModel *)shareInfo{
[TTPopup dismiss];
[XCHUDTool showErrorWithMessage:@"分享成功"];
AttachmentModel * attachMent = [[AttachmentModel alloc] init];
@@ -212,6 +237,8 @@
attachMent.data = dic;
NSString *sessionID = [NSString stringWithFormat:@"%ld", [self.hostDelegate getRoomInfo].roomId];
[IMMessageHelper sendCustomMessage:attachMent sessionId:sessionID type:NIMSessionTypeChatroom userInfo:userInfo];
///
[self saveShare:shareInfo];
}
- (void)shareViewDidClickCancel:(XPShareView *)shareView {

View File

@@ -18,7 +18,18 @@
#import <MJExtension/MJExtension.h>
#import <RPSDK/RPSDK.h>
@interface WeakWebViewScriptMessageDelegate : NSObject<WKScriptMessageHandler, XCShareViewDelegate>
typedef NS_ENUM(NSUInteger, RightNavigationPushType){
///h5
RightNavigationPushType_Web = 1,
///
RightNavigationPushType_Share = 2,
///
RightNavigationPushType_AppPage = 3,
///
RightNavigationPushType_SharePicture = 5
};
@interface WeakWebViewScriptMessageDelegate : NSObject<WKScriptMessageHandler>
//WKScriptMessageHandler JavaScriptOC
@property (nonatomic, weak) id<WKScriptMessageHandler> scriptDelegate;
@@ -52,7 +63,8 @@
@property (strong, nonatomic) WKWebView *webview;
@property (strong, nonatomic) UIProgressView *progressView;
@property (nonatomic, strong) WKUserContentController *userContentController;
///
@property (nonatomic,copy) NSDictionary *shareDic;
@end
NSString * const kJSOpenPurse = @"openPurse";
@@ -63,6 +75,7 @@ NSString * const kJSGetDeviceId = @"getDeviceId";
NSString * const kJSGetTicket = @"getTicket";
NSString * const kJSGetDeviceInfo = @"getDeviceInfo";
NSString * const kJSOpenFaceLiveness = @"openFaceLiveness";
NSString * const kJSInitNav = @"initNav";
@implementation XPWebViewController
@@ -94,7 +107,17 @@ NSString * const kJSOpenFaceLiveness = @"openFaceLiveness";
NSString *currentUrl = [NSString stringWithFormat:@"%@", response];
if (currentUrl != nil && [currentUrl containsString:API_HOST_URL]) {
if ([message.name isEqualToString:kJSOpenSharePage]) {
[self showSharePanel];
if (message.body && message.body != [NSNull null]) {
NSDictionary *body;
//dic
if ([message.body isKindOfClass:[NSDictionary class]]) {
body = message.body;
} else if ([message.body isKindOfClass:[NSString class]]) {
body = [message.body toJSONObject];
}
self.shareDic = body[@"data"];
[self showSharePanel];
}
} else if ([message.name isEqualToString:kJSGetUid]) {
NSString *uid = [[AccountInfoStorage instance] getUid];
NSString *js = [NSString stringWithFormat:@"getMessage(\"uid\",%@)", uid];
@@ -144,7 +167,9 @@ NSString * const kJSOpenFaceLiveness = @"openFaceLiveness";
}];
}];
#endif
}
} else if([message.name isEqualToString:kJSInitNav]) {
[self initNav:message.body];
}
}
}];
}
@@ -184,19 +209,50 @@ NSString * const kJSOpenFaceLiveness = @"openFaceLiveness";
[self.userContentController removeAllUserScripts];
}
}
#pragma mark -
- (void)initNav:(NSDictionary *)response{
if(!response || ![response isKindOfClass:[NSDictionary class]])return;
self.shareDic = response[@"data"];
if ([response[@"type"] intValue]== RightNavigationPushType_Web) {
[self addNavigationItemWithTitles:@[response[@"data"][@"title"]] titleColor:[ThemeColor alertTitleColor] isLeft:NO target:self action:@selector(gotoWebView) tags:nil];
}else if ([response[@"type"] intValue]== RightNavigationPushType_Share || [response[@"type"] intValue]== RightNavigationPushType_SharePicture){
[self addNavigationItemWithImageNames:@[@"family_person_share"] isLeft:NO
target:self action:@selector(showSharePanel) tags:nil];
}
}
- (void)gotoWebView {
if (self.shareDic[@"link"]) {
XPWebViewController * webVC = [[XPWebViewController alloc] init];
webVC.url = self.shareDic[@"link"];
[self.navigationController pushViewController:webVC animated:YES];
}
}
- (void)showSharePanel {
XPShareItem *cycle = [XPShareItem itemWitTag:XPShareItemTagMoments title:@"朋友圈" imageName:@"share_wechat_circle_normal" disableImageName:@"share_wechat_circle_disable"];
XPShareItem *wechat = [XPShareItem itemWitTag:XPShareItemTagMoments title:@"微信好友" imageName:@"share_wechat_normal" disableImageName:@"share_wechat_disable"];
XPShareItem *qq = [XPShareItem itemWitTag:XPShareItemTagMoments title:@"QQ好友" imageName:@"share_qq_normal" disableImageName:@"share_qq_disable"];
XPShareItem *qqzone = [XPShareItem itemWitTag:XPShareItemTagMoments title:@"QQ空间" imageName:@"share_qqzone_normal" disableImageName:@"share_qqzone_disable"];
NSArray * items = @[wechat,cycle, qq, qqzone];
if (self.shareDic.allKeys.count <= 0) {
return;
}
NSDictionary * dic = self.shareDic;
XPShareInfoModel * shareInfo = [[XPShareInfoModel alloc] init];
shareInfo.shareTitle = @"玩和平精英赢奖金";
shareInfo.shareContent = @"免费报名,奖金高,比赛多";
shareInfo.shareImageUrl = @"";
NSString * urlString = @"";
shareInfo.shareUrl = urlString;
shareInfo.shareTitle = self.shareDic[@"title"];
shareInfo.shareContent = dic[@"desc"];
shareInfo.shareImageUrl = dic[@"imgUrl"];
shareInfo.type = ShareType_H5;
NSString *urlStr = ((NSString *)dic[@"url"]).length > 0 ? dic[@"url"] : dic[@"showUrl"];
if (urlStr.length) {
if ([urlStr containsString:@"?"]) {
urlStr = [NSString stringWithFormat:@"%@&shareUid=%@",urlStr,[AccountInfoStorage instance].getUid];
} else {
urlStr = [NSString stringWithFormat:@"%@?shareUid=%@",urlStr,[AccountInfoStorage instance].getUid];
}
}
shareInfo.shareUrl = urlStr;
XPShareItem *cycle = [XPShareItem itemWitTag:XPShareItemTagMoments title:@"朋友圈" imageName:@"share_wechat_circle_normal" disableImageName:@"share_wechat_circle_disable"];
XPShareItem *wechat = [XPShareItem itemWitTag:XPShareItemTagWeChat title:@"微信好友" imageName:@"share_wechat_normal" disableImageName:@"share_wechat_disable"];
XPShareItem *qq = [XPShareItem itemWitTag:XPShareItemTagQQ title:@"QQ好友" imageName:@"share_qq_normal" disableImageName:@"share_qq_disable"];
XPShareItem *qqzone = [XPShareItem itemWitTag:XPShareItemTagQQZone title:@"QQ空间" imageName:@"share_qqzone_normal" disableImageName:@"share_qqzone_disable"];
NSArray * items = @[wechat,cycle, qq, qqzone];
CGFloat margin = 15;
CGSize itemSize = CGSizeMake((KScreenWidth-2*margin)/4, 65);
XPShareView *shareView = [[XPShareView alloc] initWithItems:items itemSize:itemSize shareInfo:shareInfo];
@@ -206,7 +262,34 @@ NSString * const kJSOpenFaceLiveness = @"openFaceLiveness";
#pragma mark - XCShareViewDelegate
- (void)shareViewDidClickCancle:(XPShareView *)shareView {
[TTPopup dismiss];
}
- (void)shareView:(XPShareView *)shareView didSuccess:(XPShareInfoModel *)shareInfo {
[TTPopup dismiss];
NSMutableDictionary *params = [NSMutableDictionary dictionary];
NSString *uid = [AccountInfoStorage instance].getUid;
NSString *ticket = [AccountInfoStorage instance].getTicket;
[params setObject:uid forKey:@"uid"];
[params setObject:@(shareInfo.shareType) forKey:@"shareType"];
[params setObject:ticket forKey:@"ticket"];
[params setObject:@(shareInfo.type) forKey:@"sharePageId"];
if (shareInfo.shareUrl.length > 0) {
[params setObject:shareInfo.shareUrl forKey:@"shareUrl"];
}
if (shareInfo.roomUid > 0) {
[params setObject:@(shareInfo.roomUid) forKey:@"targetUid"];
}
[HttpRequestHelper POST:@"usershare/save" params:params success:^(BaseModel * _Nonnull data) {
} failure:^(NSInteger resCode, NSString * _Nonnull message) {
}];
}
- (void)shareView:(XPShareView *)shareView shareFail:(NSString *)message {
[TTPopup dismiss];
[self showErrorToast:message];
}
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
@@ -324,6 +407,8 @@ NSString * const kJSOpenFaceLiveness = @"openFaceLiveness";
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSGetDeviceInfo];
// :
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSOpenFaceLiveness];
//
[_userContentController addScriptMessageHandler:weakScriptMessageDelegate name:kJSInitNav];
}
return _userContentController;