两折卖----返利app-----返利圈

WXApiRequestHandler.m 11KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. //
  2. // WXApiManager.m
  3. // SDKSample
  4. //
  5. // Created by Jeason on 15/7/14.
  6. //
  7. //
  8. #import "WXApi.h"
  9. #import "WXApiRequestHandler.h"
  10. #import "WXApiManager.h"
  11. #import "SendMessageToWXReq+requestWithTextOrMediaMessage.h"
  12. #import "WXMediaMessage+messageConstruct.h"
  13. @implementation WXApiRequestHandler
  14. #pragma mark - Public Methods
  15. + (BOOL)sendText:(NSString *)text
  16. InScene:(enum WXScene)scene {
  17. SendMessageToWXReq *req = [SendMessageToWXReq requestWithText:text
  18. OrMediaMessage:nil
  19. bText:YES
  20. InScene:scene];
  21. return [WXApi sendReq:req];
  22. }
  23. + (BOOL)sendImageData:(NSData *)imageData
  24. TagName:(NSString *)tagName
  25. MessageExt:(NSString *)messageExt
  26. Action:(NSString *)action
  27. ThumbImage:(UIImage *)thumbImage
  28. InScene:(enum WXScene)scene {
  29. WXImageObject *ext = [WXImageObject object];
  30. ext.imageData = imageData;
  31. WXMediaMessage *message = [WXMediaMessage messageWithTitle:nil
  32. Description:nil
  33. Object:ext
  34. MessageExt:messageExt
  35. MessageAction:action
  36. ThumbImage:thumbImage
  37. MediaTag:tagName];
  38. SendMessageToWXReq* req = [SendMessageToWXReq requestWithText:nil
  39. OrMediaMessage:message
  40. bText:NO
  41. InScene:scene];
  42. return [WXApi sendReq:req];
  43. }
  44. + (BOOL)sendLinkURL:(NSString *)urlString
  45. TagName:(NSString *)tagName
  46. Title:(NSString *)title
  47. Description:(NSString *)description
  48. ThumbImage:(UIImage *)thumbImage
  49. InScene:(enum WXScene)scene {
  50. WXWebpageObject *ext = [WXWebpageObject object];
  51. ext.webpageUrl = urlString;
  52. WXMediaMessage *message = [WXMediaMessage messageWithTitle:title
  53. Description:description
  54. Object:ext
  55. MessageExt:nil
  56. MessageAction:nil
  57. ThumbImage:thumbImage
  58. MediaTag:tagName];
  59. SendMessageToWXReq* req = [SendMessageToWXReq requestWithText:nil
  60. OrMediaMessage:message
  61. bText:NO
  62. InScene:scene];
  63. return [WXApi sendReq:req];
  64. }
  65. + (BOOL)sendMusicURL:(NSString *)musicURL
  66. dataURL:(NSString *)dataURL
  67. Title:(NSString *)title
  68. Description:(NSString *)description
  69. ThumbImage:(UIImage *)thumbImage
  70. InScene:(enum WXScene)scene {
  71. WXMusicObject *ext = [WXMusicObject object];
  72. ext.musicUrl = musicURL;
  73. ext.musicDataUrl = dataURL;
  74. WXMediaMessage *message = [WXMediaMessage messageWithTitle:title
  75. Description:description
  76. Object:ext
  77. MessageExt:nil
  78. MessageAction:nil
  79. ThumbImage:thumbImage
  80. MediaTag:nil];
  81. SendMessageToWXReq* req = [SendMessageToWXReq requestWithText:nil
  82. OrMediaMessage:message
  83. bText:NO
  84. InScene:scene];
  85. return [WXApi sendReq:req];
  86. }
  87. + (BOOL)sendVideoURL:(NSString *)videoURL
  88. Title:(NSString *)title
  89. Description:(NSString *)description
  90. ThumbImage:(UIImage *)thumbImage
  91. InScene:(enum WXScene)scene {
  92. WXMediaMessage *message = [WXMediaMessage message];
  93. message.title = title;
  94. message.description = description;
  95. [message setThumbImage:thumbImage];
  96. WXVideoObject *ext = [WXVideoObject object];
  97. ext.videoUrl = videoURL;
  98. message.mediaObject = ext;
  99. SendMessageToWXReq* req = [SendMessageToWXReq requestWithText:nil
  100. OrMediaMessage:message
  101. bText:NO
  102. InScene:scene];
  103. return [WXApi sendReq:req];
  104. }
  105. + (BOOL)sendEmotionData:(NSData *)emotionData
  106. ThumbImage:(UIImage *)thumbImage
  107. InScene:(enum WXScene)scene {
  108. WXMediaMessage *message = [WXMediaMessage message];
  109. [message setThumbImage:thumbImage];
  110. WXEmoticonObject *ext = [WXEmoticonObject object];
  111. ext.emoticonData = emotionData;
  112. message.mediaObject = ext;
  113. SendMessageToWXReq* req = [SendMessageToWXReq requestWithText:nil
  114. OrMediaMessage:message
  115. bText:NO
  116. InScene:scene];
  117. return [WXApi sendReq:req];
  118. }
  119. + (BOOL)sendFileData:(NSData *)fileData
  120. fileExtension:(NSString *)extension
  121. Title:(NSString *)title
  122. Description:(NSString *)description
  123. ThumbImage:(UIImage *)thumbImage
  124. InScene:(enum WXScene)scene {
  125. WXMediaMessage *message = [WXMediaMessage message];
  126. message.title = title;
  127. message.description = description;
  128. [message setThumbImage:thumbImage];
  129. WXFileObject *ext = [WXFileObject object];
  130. ext.fileExtension = @"pdf";
  131. ext.fileData = fileData;
  132. message.mediaObject = ext;
  133. SendMessageToWXReq* req = [SendMessageToWXReq requestWithText:nil
  134. OrMediaMessage:message
  135. bText:NO
  136. InScene:scene];
  137. return [WXApi sendReq:req];
  138. }
  139. + (BOOL)sendAppContentData:(NSData *)data
  140. ExtInfo:(NSString *)info
  141. ExtURL:(NSString *)url
  142. Title:(NSString *)title
  143. Description:(NSString *)description
  144. MessageExt:(NSString *)messageExt
  145. MessageAction:(NSString *)action
  146. ThumbImage:(UIImage *)thumbImage
  147. InScene:(enum WXScene)scene {
  148. WXAppExtendObject *ext = [WXAppExtendObject object];
  149. ext.extInfo = info;
  150. ext.url = url;
  151. ext.fileData = data;
  152. WXMediaMessage *message = [WXMediaMessage messageWithTitle:title
  153. Description:description
  154. Object:ext
  155. MessageExt:messageExt
  156. MessageAction:action
  157. ThumbImage:thumbImage
  158. MediaTag:nil];
  159. SendMessageToWXReq* req = [SendMessageToWXReq requestWithText:nil
  160. OrMediaMessage:message
  161. bText:NO
  162. InScene:scene];
  163. return [WXApi sendReq:req];
  164. }
  165. + (BOOL)addCardsToCardPackage:(NSArray *)cardItems {
  166. AddCardToWXCardPackageReq *req = [[AddCardToWXCardPackageReq alloc] init];
  167. req.cardAry = cardItems;
  168. return [WXApi sendReq:req];
  169. }
  170. + (BOOL)sendAuthRequestScope:(NSString *)scope
  171. State:(NSString *)state
  172. OpenID:(NSString *)openID
  173. InViewController:(UIViewController *)viewController {
  174. SendAuthReq* req = [[SendAuthReq alloc] init];
  175. req.scope = scope; // @"post_timeline,sns"
  176. req.state = state;
  177. req.openID = openID;
  178. return [WXApi sendAuthReq:req
  179. viewController:viewController
  180. delegate:[WXApiManager sharedManager]];
  181. }
  182. + (BOOL)jumpToBizWebviewWithAppID:(NSString *)appID
  183. Description:(NSString *)description
  184. tousrname:(NSString *)tousrname
  185. ExtMsg:(NSString *)extMsg {
  186. [WXApi registerApp:appID];
  187. JumpToBizWebviewReq *req = [[JumpToBizWebviewReq alloc]init];
  188. req.tousrname = tousrname;
  189. req.extMsg = extMsg;
  190. req.webType = WXMPWebviewType_Ad;
  191. return [WXApi sendReq:req];
  192. }
  193. + (NSString *)jumpToBizPay {
  194. //============================================================
  195. // V3&V4支付流程实现
  196. // 注意:参数配置请查看服务器端Demo
  197. // 更新时间:2015年11月20日
  198. //============================================================
  199. NSString *urlString = @"http://wxpay.weixin.qq.com/pub_v2/app/app_pay.php?plat=ios";
  200. //解析服务端返回json数据
  201. NSError *error;
  202. //加载一个NSURL对象
  203. NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
  204. //将请求的url数据放到NSData对象中
  205. NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
  206. if ( response != nil) {
  207. NSMutableDictionary *dict = NULL;
  208. //IOS5自带解析类NSJSONSerialization从response中解析出数据放到字典中
  209. dict = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableLeaves error:&error];
  210. NSLog(@"url:%@",urlString);
  211. if(dict != nil){
  212. NSMutableString *retcode = [dict objectForKey:@"retcode"];
  213. if (retcode.intValue == 0){
  214. NSMutableString *stamp = [dict objectForKey:@"timestamp"];
  215. #if 0
  216. //调起微信支付
  217. PayReq* req = [[PayReq alloc] init];
  218. req.partnerId = [dict objectForKey:@"partnerid"];
  219. req.prepayId = [dict objectForKey:@"prepayid"];
  220. req.nonceStr = [dict objectForKey:@"noncestr"];
  221. req.timeStamp = stamp.intValue;
  222. req.package = [dict objectForKey:@"package"];
  223. req.sign = [dict objectForKey:@"sign"];
  224. [WXApi sendReq:req];
  225. //日志输出
  226. NSLog(@"appid=%@\npartid=%@\nprepayid=%@\nnoncestr=%@\ntimestamp=%ld\npackage=%@\nsign=%@",[dict objectForKey:@"appid"],req.partnerId,req.prepayId,req.nonceStr,(long)req.timeStamp,req.package,req.sign );
  227. #endif
  228. return @"";
  229. }else{
  230. return [dict objectForKey:@"retmsg"];
  231. }
  232. }else{
  233. return @"服务器返回错误,未获取到json对象";
  234. }
  235. }else{
  236. return @"服务器返回错误";
  237. }
  238. }
  239. @end