天天省钱快报

WXApiResponseHandler.m 7.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. //
  2. // WXApiResponseManager.m
  3. // SDKSample
  4. //
  5. // Created by Jeason on 15/7/14.
  6. //
  7. //
  8. #import "WXApi.h"
  9. #import "WXApiResponseHandler.h"
  10. #import "GetMessageFromWXResp+responseWithTextOrMediaMessage.h"
  11. #import "WXMediaMessage+messageConstruct.h"
  12. @implementation WXApiResponseHandler
  13. #pragma mark - Public Methods
  14. + (BOOL)respText:(NSString *)text {
  15. GetMessageFromWXResp *resp = [GetMessageFromWXResp responseWithText:text
  16. OrMediaMessage:nil
  17. bText:YES];
  18. return [WXApi sendResp:resp];
  19. }
  20. + (BOOL)respImageData:(NSData *)imageData
  21. MessageExt:(NSString *)messageExt
  22. Action:(NSString *)action
  23. ThumbImage:(UIImage *)thumbImage {
  24. WXImageObject *ext = [WXImageObject object];
  25. ext.imageData = imageData;
  26. WXMediaMessage *message = [WXMediaMessage messageWithTitle:nil
  27. Description:nil
  28. Object:ext
  29. MessageExt:messageExt
  30. MessageAction:action
  31. ThumbImage:thumbImage
  32. MediaTag:nil];
  33. GetMessageFromWXResp* resp = [GetMessageFromWXResp responseWithText:nil
  34. OrMediaMessage:message
  35. bText:NO];
  36. return [WXApi sendResp:resp];
  37. }
  38. + (BOOL)respLinkURL:(NSString *)urlString
  39. Title:(NSString *)title
  40. Description:(NSString *)description
  41. ThumbImage:(UIImage *)thumbImage {
  42. WXWebpageObject *ext = [WXWebpageObject object];
  43. ext.webpageUrl = urlString;
  44. WXMediaMessage *message = [WXMediaMessage messageWithTitle:title
  45. Description:description
  46. Object:ext
  47. MessageExt:nil
  48. MessageAction:nil
  49. ThumbImage:thumbImage
  50. MediaTag:nil];
  51. GetMessageFromWXResp* resp = [GetMessageFromWXResp responseWithText:nil
  52. OrMediaMessage:message
  53. bText:NO];
  54. return [WXApi sendResp:resp];
  55. }
  56. + (BOOL)respMusicURL:(NSString *)musicURL
  57. dataURL:(NSString *)dataURL
  58. Title:(NSString *)title
  59. Description:(NSString *)description
  60. ThumbImage:(UIImage *)thumbImage {
  61. WXMediaMessage *message = [WXMediaMessage message];
  62. message.title = title;
  63. message.description = description;
  64. [message setThumbImage:thumbImage];
  65. WXMusicObject *ext = [WXMusicObject object];
  66. ext.musicUrl = musicURL;
  67. ext.musicDataUrl = dataURL;
  68. message.mediaObject = ext;
  69. GetMessageFromWXResp* resp = [GetMessageFromWXResp responseWithText:nil
  70. OrMediaMessage:message
  71. bText:NO];
  72. return [WXApi sendResp:resp];
  73. }
  74. + (BOOL)respVideoURL:(NSString *)videoURL
  75. Title:(NSString *)title
  76. Description:(NSString *)description
  77. ThumbImage:(UIImage *)thumbImage {
  78. WXVideoObject *ext = [WXVideoObject object];
  79. ext.videoUrl = videoURL;
  80. WXMediaMessage *message = [WXMediaMessage messageWithTitle:title
  81. Description:description
  82. Object:ext
  83. MessageExt:nil
  84. MessageAction:nil
  85. ThumbImage:thumbImage
  86. MediaTag:nil];
  87. GetMessageFromWXResp* resp = [GetMessageFromWXResp responseWithText:nil
  88. OrMediaMessage:message
  89. bText:NO];
  90. return [WXApi sendResp:resp];
  91. }
  92. + (BOOL)respEmotionData:(NSData *)emotionData
  93. ThumbImage:(UIImage *)thumbImage {
  94. WXEmoticonObject *ext = [WXEmoticonObject object];
  95. ext.emoticonData = emotionData;
  96. WXMediaMessage *message = [WXMediaMessage messageWithTitle:nil
  97. Description:nil
  98. Object:ext
  99. MessageExt:nil
  100. MessageAction:nil
  101. ThumbImage:thumbImage
  102. MediaTag:nil];
  103. GetMessageFromWXResp* resp = [GetMessageFromWXResp responseWithText:nil
  104. OrMediaMessage:message
  105. bText:NO];
  106. return [WXApi sendResp:resp];
  107. }
  108. + (BOOL)respFileData:(NSData *)fileData
  109. fileExtension:(NSString *)extension
  110. Title:(NSString *)title
  111. Description:(NSString *)description
  112. ThumbImage:(UIImage *)thumbImage {
  113. WXFileObject *ext = [WXFileObject object];
  114. ext.fileExtension = extension;
  115. ext.fileData = fileData;
  116. WXMediaMessage *message = [WXMediaMessage messageWithTitle:title
  117. Description:description
  118. Object:ext
  119. MessageExt:nil
  120. MessageAction:nil
  121. ThumbImage:thumbImage
  122. MediaTag:nil];
  123. GetMessageFromWXResp* resp = [GetMessageFromWXResp responseWithText:nil
  124. OrMediaMessage:message
  125. bText:NO];
  126. return [WXApi sendResp:resp];
  127. }
  128. + (BOOL)respAppContentData:(NSData *)data
  129. ExtInfo:(NSString *)info
  130. ExtURL:(NSString *)url
  131. Title:(NSString *)title
  132. Description:(NSString *)description
  133. MessageExt:(NSString *)messageExt
  134. MessageAction:(NSString *)action
  135. ThumbImage:(UIImage *)thumbImage {
  136. WXAppExtendObject *ext = [WXAppExtendObject object];
  137. ext.extInfo = info;
  138. ext.url = url;
  139. ext.fileData = data;
  140. WXMediaMessage *message = [WXMediaMessage messageWithTitle:title
  141. Description:description
  142. Object:ext
  143. MessageExt:messageExt
  144. MessageAction:action
  145. ThumbImage:thumbImage
  146. MediaTag:nil];
  147. GetMessageFromWXResp* resp = [GetMessageFromWXResp responseWithText:nil
  148. OrMediaMessage:message
  149. bText:NO];
  150. return [WXApi sendResp:resp];
  151. }
  152. @end