├── .gitignore ├── README.md ├── 微信支付.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ ├── contents.xcworkspacedata │ └── xcuserdata │ │ └── admin.xcuserdatad │ │ └── UserInterfaceState.xcuserstate └── xcuserdata │ └── admin.xcuserdatad │ ├── xcdebugger │ └── Breakpoints_v2.xcbkptlist │ └── xcschemes │ ├── xcschememanagement.plist │ └── 微信支付.xcscheme ├── 微信支付 ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ ├── LaunchScreen.xib │ └── Main.storyboard ├── GBWXPay │ ├── GBWXPayManager │ │ ├── GBWXPayManager.h │ │ ├── GBWXPayManager.m │ │ └── GBWXPayManagerConfig.h │ └── WxPay │ │ ├── SDKExport │ │ ├── WXApi.h │ │ ├── WXApiObject.h │ │ └── libWeChatSDK.a │ │ └── lib │ │ ├── ApiXml.h │ │ ├── ApiXml.mm │ │ ├── WXUtil.h │ │ ├── WXUtil.mm │ │ ├── payRequsestHandler.h │ │ └── payRequsestHandler.mm ├── Images.xcassets │ └── AppIcon.appiconset │ │ └── Contents.json ├── Info.plist ├── ViewController.h ├── ViewController.m └── main.m └── 微信支付Tests ├── Info.plist └── ____Tests.m /.gitignore: -------------------------------------------------------------------------------- 1 | # Xcode 2 | # 3 | build/ 4 | *.pbxuser 5 | !default.pbxuser 6 | *.mode1v3 7 | !default.mode1v3 8 | *.mode2v3 9 | !default.mode2v3 10 | *.perspectivev3 11 | !default.perspectivev3 12 | xcuserdata 13 | *.xccheckout 14 | *.moved-aside 15 | DerivedData 16 | *.hmap 17 | *.ipa 18 | *.xcuserstate 19 | 20 | # CocoaPods 21 | # 22 | # We recommend against adding the Pods directory to your .gitignore. However 23 | # you should judge for yourself, the pros and cons are mentioned at: 24 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 25 | # 26 | #Pods/ 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | #GBWXPay
2 | ##如果觉得有用的话请点个星谢谢支持,会继续出一些功能性的框架,如有bug也请指出群号:433060483欢迎加入组织 3 | #简介:
4 | ## 鉴于微信支付官方文档写的比较乱,特意总结了一下微信支付,即使你没有看过微信支付的官方文档只要按照使用说明来操作也可以为你的项目添加微信支付功能
5 | #使用说明
6 | * 直接把GBWXPay文件拖到你的工程里面
7 | * 配置一下系统库libsqlite3.0.dylib、libz.dzlib、SystemConfiguration.frame添加到自己的项目中去,编译一下如果没有问题,就进行下一步,如果有问题可能提示查无此类,不要紧在相应的类里面包含一下#import 就ok了,如果你的pch里面包含了那就更好了这个地方就不会报错
8 | * 编译无错的话那就在应用的地方包含一下我的管理文件的头文件#import "GBWXPayManager.h",直接调用里面的方法实现支付功能
9 | * 配置appdelegate,先包含#import "GBWXPayManager.h"头文件,此外注意微信支付调用回调的时候用的时协议代理,这里要在appdelegate里面包含一下代理协议,复制以下代码:
10 | ``` 11 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 12 | 13 | //向微信注册 14 | [WXApi registerApp:APP_ID withDescription:nil]; 15 | return YES; 16 | } 17 | #pragma mark - 微信支付回调 18 | -(void) onResp:(BaseResp*)resp 19 | { 20 | NSString *strMsg = [NSString stringWithFormat:@"errcode:%d", resp.errCode]; 21 | NSString *strTitle; 22 | 23 | if([resp isKindOfClass:[SendMessageToWXResp class]]) 24 | { 25 | strTitle = [NSString stringWithFormat:@"发送媒体消息结果"]; 26 | } 27 | if([resp isKindOfClass:[PayResp class]]){ 28 | //支付返回结果,实际支付结果需要去微信服务器端查询 29 | strTitle = [NSString stringWithFormat:@"支付结果"]; 30 | 31 | switch (resp.errCode) { 32 | case WXSuccess: 33 | strMsg = @"支付结果:成功!"; 34 | NSLog(@"支付成功-PaySuccess,retcode = %d", resp.errCode); 35 | [[NSNotificationCenter defaultCenter] postNotificationName:@"WXpayresult" object:@"1"]; 36 | break; 37 | 38 | default: 39 | strMsg = [NSString stringWithFormat:@"支付结果:失败!retcode = %d, retstr = %@", resp.errCode,resp.errStr]; 40 | NSLog(@"错误,retcode = %d, retstr = %@", resp.errCode,resp.errStr); 41 | break; 42 | } 43 | } 44 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitle message:strMsg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 45 | [alert show]; 46 | } 47 | 48 | - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 49 | { 50 | return [WXApi handleOpenURL:url delegate:self]; 51 | } 52 | ``` 53 | * 在实现支付功能的类里面注册监听处理支付成功回调和失败回调,具体看demo
54 | * 接下来就要设置回调参数,实现app支付完成的回调了 55 | 点击项目名称,点击“Info”选项卡,在URL types里面添加一项,Identifier可以不填,URL schemes就是appid直接复制进去就ok了
56 | 57 | ##具体的使用说明在代码里面也有,如果你参数要写在本地的话,请在GBWXPayManagerConfig.h里完成配置,这样便于维护你的代码
58 | ##调用的时候复制代码:
59 | ``` 60 | [GBWXPayManager wxpayWithOrderID:orderno orderTitle:@"测试" amount:@"0.01"]; 61 | ``` 62 | #更新说明:
63 | * 更新最新的SDK避免因为IPV6的原因被拒的风险
64 | * 账号密钥被商户改了不能给大家提供免费测试账户了,现在会报签名失败的错误,自己替换自己的账号即可。
65 | 66 | 67 | # 看一下效果图:
68 | ![image](https://github.com/mokey1422/gifResource/blob/master/weixinpay.gif) 69 | 70 | -------------------------------------------------------------------------------- /微信支付.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 84719E221B62971A00934D9C /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 84719E211B62971A00934D9C /* main.m */; }; 11 | 84719E251B62971A00934D9C /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 84719E241B62971A00934D9C /* AppDelegate.m */; }; 12 | 84719E281B62971A00934D9C /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = 84719E271B62971A00934D9C /* ViewController.m */; }; 13 | 84719E2B1B62971A00934D9C /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 84719E291B62971A00934D9C /* Main.storyboard */; }; 14 | 84719E2D1B62971A00934D9C /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 84719E2C1B62971A00934D9C /* Images.xcassets */; }; 15 | 84719E301B62971A00934D9C /* LaunchScreen.xib in Resources */ = {isa = PBXBuildFile; fileRef = 84719E2E1B62971A00934D9C /* LaunchScreen.xib */; }; 16 | 84719E3C1B62971A00934D9C /* ____Tests.m in Sources */ = {isa = PBXBuildFile; fileRef = 84719E3B1B62971A00934D9C /* ____Tests.m */; }; 17 | 84719E661B62985A00934D9C /* libsqlite3.0.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 84719E651B62985A00934D9C /* libsqlite3.0.dylib */; }; 18 | 84719E681B62987100934D9C /* libz.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 84719E671B62987100934D9C /* libz.dylib */; }; 19 | 84719E6A1B62988000934D9C /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 84719E691B62988000934D9C /* SystemConfiguration.framework */; }; 20 | 848B10C51BCA291100A76381 /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 848B10C41BCA291100A76381 /* CoreTelephony.framework */; }; 21 | 84A622861B6324FD00515D33 /* GBWXPayManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 84A622781B6324FD00515D33 /* GBWXPayManager.m */; }; 22 | 84A622871B6324FD00515D33 /* ApiXml.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A6227D1B6324FD00515D33 /* ApiXml.mm */; }; 23 | 84A622881B6324FD00515D33 /* payRequsestHandler.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A6227F1B6324FD00515D33 /* payRequsestHandler.mm */; }; 24 | 84A622891B6324FD00515D33 /* WXUtil.mm in Sources */ = {isa = PBXBuildFile; fileRef = 84A622811B6324FD00515D33 /* WXUtil.mm */; }; 25 | 84A6228A1B6324FD00515D33 /* libWeChatSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 84A622831B6324FD00515D33 /* libWeChatSDK.a */; }; 26 | /* End PBXBuildFile section */ 27 | 28 | /* Begin PBXContainerItemProxy section */ 29 | 84719E361B62971A00934D9C /* PBXContainerItemProxy */ = { 30 | isa = PBXContainerItemProxy; 31 | containerPortal = 84719E141B62971900934D9C /* Project object */; 32 | proxyType = 1; 33 | remoteGlobalIDString = 84719E1B1B62971A00934D9C; 34 | remoteInfo = "微信支付"; 35 | }; 36 | /* End PBXContainerItemProxy section */ 37 | 38 | /* Begin PBXFileReference section */ 39 | 84719E1C1B62971A00934D9C /* 微信支付.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "微信支付.app"; sourceTree = BUILT_PRODUCTS_DIR; }; 40 | 84719E201B62971A00934D9C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 41 | 84719E211B62971A00934D9C /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 42 | 84719E231B62971A00934D9C /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 43 | 84719E241B62971A00934D9C /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 44 | 84719E261B62971A00934D9C /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 45 | 84719E271B62971A00934D9C /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 46 | 84719E2A1B62971A00934D9C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 47 | 84719E2C1B62971A00934D9C /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 48 | 84719E2F1B62971A00934D9C /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = Base.lproj/LaunchScreen.xib; sourceTree = ""; }; 49 | 84719E351B62971A00934D9C /* 微信支付Tests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = "微信支付Tests.xctest"; sourceTree = BUILT_PRODUCTS_DIR; }; 50 | 84719E3A1B62971A00934D9C /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 51 | 84719E3B1B62971A00934D9C /* ____Tests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "____Tests.m"; sourceTree = ""; }; 52 | 84719E651B62985A00934D9C /* libsqlite3.0.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libsqlite3.0.dylib; path = usr/lib/libsqlite3.0.dylib; sourceTree = SDKROOT; }; 53 | 84719E671B62987100934D9C /* libz.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; name = libz.dylib; path = usr/lib/libz.dylib; sourceTree = SDKROOT; }; 54 | 84719E691B62988000934D9C /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; 55 | 848B10C41BCA291100A76381 /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; }; 56 | 84A622771B6324FD00515D33 /* GBWXPayManager.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GBWXPayManager.h; sourceTree = ""; }; 57 | 84A622781B6324FD00515D33 /* GBWXPayManager.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GBWXPayManager.m; sourceTree = ""; }; 58 | 84A622791B6324FD00515D33 /* GBWXPayManagerConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = GBWXPayManagerConfig.h; sourceTree = ""; }; 59 | 84A6227C1B6324FD00515D33 /* ApiXml.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ApiXml.h; sourceTree = ""; }; 60 | 84A6227D1B6324FD00515D33 /* ApiXml.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ApiXml.mm; sourceTree = ""; }; 61 | 84A6227E1B6324FD00515D33 /* payRequsestHandler.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = payRequsestHandler.h; sourceTree = ""; }; 62 | 84A6227F1B6324FD00515D33 /* payRequsestHandler.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = payRequsestHandler.mm; sourceTree = ""; }; 63 | 84A622801B6324FD00515D33 /* WXUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXUtil.h; sourceTree = ""; }; 64 | 84A622811B6324FD00515D33 /* WXUtil.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = WXUtil.mm; sourceTree = ""; }; 65 | 84A622831B6324FD00515D33 /* libWeChatSDK.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libWeChatSDK.a; sourceTree = ""; }; 66 | 84A622841B6324FD00515D33 /* WXApi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXApi.h; sourceTree = ""; }; 67 | 84A622851B6324FD00515D33 /* WXApiObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXApiObject.h; sourceTree = ""; }; 68 | /* End PBXFileReference section */ 69 | 70 | /* Begin PBXFrameworksBuildPhase section */ 71 | 84719E191B62971A00934D9C /* Frameworks */ = { 72 | isa = PBXFrameworksBuildPhase; 73 | buildActionMask = 2147483647; 74 | files = ( 75 | 848B10C51BCA291100A76381 /* CoreTelephony.framework in Frameworks */, 76 | 84719E6A1B62988000934D9C /* SystemConfiguration.framework in Frameworks */, 77 | 84719E681B62987100934D9C /* libz.dylib in Frameworks */, 78 | 84A6228A1B6324FD00515D33 /* libWeChatSDK.a in Frameworks */, 79 | 84719E661B62985A00934D9C /* libsqlite3.0.dylib in Frameworks */, 80 | ); 81 | runOnlyForDeploymentPostprocessing = 0; 82 | }; 83 | 84719E321B62971A00934D9C /* Frameworks */ = { 84 | isa = PBXFrameworksBuildPhase; 85 | buildActionMask = 2147483647; 86 | files = ( 87 | ); 88 | runOnlyForDeploymentPostprocessing = 0; 89 | }; 90 | /* End PBXFrameworksBuildPhase section */ 91 | 92 | /* Begin PBXGroup section */ 93 | 84719E131B62971900934D9C = { 94 | isa = PBXGroup; 95 | children = ( 96 | 848B10C41BCA291100A76381 /* CoreTelephony.framework */, 97 | 84719E691B62988000934D9C /* SystemConfiguration.framework */, 98 | 84719E671B62987100934D9C /* libz.dylib */, 99 | 84719E651B62985A00934D9C /* libsqlite3.0.dylib */, 100 | 84719E1E1B62971A00934D9C /* 微信支付 */, 101 | 84719E381B62971A00934D9C /* 微信支付Tests */, 102 | 84719E1D1B62971A00934D9C /* Products */, 103 | ); 104 | sourceTree = ""; 105 | }; 106 | 84719E1D1B62971A00934D9C /* Products */ = { 107 | isa = PBXGroup; 108 | children = ( 109 | 84719E1C1B62971A00934D9C /* 微信支付.app */, 110 | 84719E351B62971A00934D9C /* 微信支付Tests.xctest */, 111 | ); 112 | name = Products; 113 | sourceTree = ""; 114 | }; 115 | 84719E1E1B62971A00934D9C /* 微信支付 */ = { 116 | isa = PBXGroup; 117 | children = ( 118 | 84A622751B6324FD00515D33 /* GBWXPay */, 119 | 84719E231B62971A00934D9C /* AppDelegate.h */, 120 | 84719E241B62971A00934D9C /* AppDelegate.m */, 121 | 84719E261B62971A00934D9C /* ViewController.h */, 122 | 84719E271B62971A00934D9C /* ViewController.m */, 123 | 84719E291B62971A00934D9C /* Main.storyboard */, 124 | 84719E2C1B62971A00934D9C /* Images.xcassets */, 125 | 84719E2E1B62971A00934D9C /* LaunchScreen.xib */, 126 | 84719E1F1B62971A00934D9C /* Supporting Files */, 127 | ); 128 | path = "微信支付"; 129 | sourceTree = ""; 130 | }; 131 | 84719E1F1B62971A00934D9C /* Supporting Files */ = { 132 | isa = PBXGroup; 133 | children = ( 134 | 84719E201B62971A00934D9C /* Info.plist */, 135 | 84719E211B62971A00934D9C /* main.m */, 136 | ); 137 | name = "Supporting Files"; 138 | sourceTree = ""; 139 | }; 140 | 84719E381B62971A00934D9C /* 微信支付Tests */ = { 141 | isa = PBXGroup; 142 | children = ( 143 | 84719E3B1B62971A00934D9C /* ____Tests.m */, 144 | 84719E391B62971A00934D9C /* Supporting Files */, 145 | ); 146 | path = "微信支付Tests"; 147 | sourceTree = ""; 148 | }; 149 | 84719E391B62971A00934D9C /* Supporting Files */ = { 150 | isa = PBXGroup; 151 | children = ( 152 | 84719E3A1B62971A00934D9C /* Info.plist */, 153 | ); 154 | name = "Supporting Files"; 155 | sourceTree = ""; 156 | }; 157 | 84A622751B6324FD00515D33 /* GBWXPay */ = { 158 | isa = PBXGroup; 159 | children = ( 160 | 84A622761B6324FD00515D33 /* GBWXPayManager */, 161 | 84A6227A1B6324FD00515D33 /* WxPay */, 162 | ); 163 | path = GBWXPay; 164 | sourceTree = ""; 165 | }; 166 | 84A622761B6324FD00515D33 /* GBWXPayManager */ = { 167 | isa = PBXGroup; 168 | children = ( 169 | 84A622771B6324FD00515D33 /* GBWXPayManager.h */, 170 | 84A622781B6324FD00515D33 /* GBWXPayManager.m */, 171 | 84A622791B6324FD00515D33 /* GBWXPayManagerConfig.h */, 172 | ); 173 | path = GBWXPayManager; 174 | sourceTree = ""; 175 | }; 176 | 84A6227A1B6324FD00515D33 /* WxPay */ = { 177 | isa = PBXGroup; 178 | children = ( 179 | 84A6227B1B6324FD00515D33 /* lib */, 180 | 84A622821B6324FD00515D33 /* SDKExport */, 181 | ); 182 | path = WxPay; 183 | sourceTree = ""; 184 | }; 185 | 84A6227B1B6324FD00515D33 /* lib */ = { 186 | isa = PBXGroup; 187 | children = ( 188 | 84A6227C1B6324FD00515D33 /* ApiXml.h */, 189 | 84A6227D1B6324FD00515D33 /* ApiXml.mm */, 190 | 84A6227E1B6324FD00515D33 /* payRequsestHandler.h */, 191 | 84A6227F1B6324FD00515D33 /* payRequsestHandler.mm */, 192 | 84A622801B6324FD00515D33 /* WXUtil.h */, 193 | 84A622811B6324FD00515D33 /* WXUtil.mm */, 194 | ); 195 | path = lib; 196 | sourceTree = ""; 197 | }; 198 | 84A622821B6324FD00515D33 /* SDKExport */ = { 199 | isa = PBXGroup; 200 | children = ( 201 | 84A622831B6324FD00515D33 /* libWeChatSDK.a */, 202 | 84A622841B6324FD00515D33 /* WXApi.h */, 203 | 84A622851B6324FD00515D33 /* WXApiObject.h */, 204 | ); 205 | path = SDKExport; 206 | sourceTree = ""; 207 | }; 208 | /* End PBXGroup section */ 209 | 210 | /* Begin PBXNativeTarget section */ 211 | 84719E1B1B62971A00934D9C /* 微信支付 */ = { 212 | isa = PBXNativeTarget; 213 | buildConfigurationList = 84719E3F1B62971A00934D9C /* Build configuration list for PBXNativeTarget "微信支付" */; 214 | buildPhases = ( 215 | 84719E181B62971A00934D9C /* Sources */, 216 | 84719E191B62971A00934D9C /* Frameworks */, 217 | 84719E1A1B62971A00934D9C /* Resources */, 218 | ); 219 | buildRules = ( 220 | ); 221 | dependencies = ( 222 | ); 223 | name = "微信支付"; 224 | productName = "微信支付"; 225 | productReference = 84719E1C1B62971A00934D9C /* 微信支付.app */; 226 | productType = "com.apple.product-type.application"; 227 | }; 228 | 84719E341B62971A00934D9C /* 微信支付Tests */ = { 229 | isa = PBXNativeTarget; 230 | buildConfigurationList = 84719E421B62971A00934D9C /* Build configuration list for PBXNativeTarget "微信支付Tests" */; 231 | buildPhases = ( 232 | 84719E311B62971A00934D9C /* Sources */, 233 | 84719E321B62971A00934D9C /* Frameworks */, 234 | 84719E331B62971A00934D9C /* Resources */, 235 | ); 236 | buildRules = ( 237 | ); 238 | dependencies = ( 239 | 84719E371B62971A00934D9C /* PBXTargetDependency */, 240 | ); 241 | name = "微信支付Tests"; 242 | productName = "微信支付Tests"; 243 | productReference = 84719E351B62971A00934D9C /* 微信支付Tests.xctest */; 244 | productType = "com.apple.product-type.bundle.unit-test"; 245 | }; 246 | /* End PBXNativeTarget section */ 247 | 248 | /* Begin PBXProject section */ 249 | 84719E141B62971900934D9C /* Project object */ = { 250 | isa = PBXProject; 251 | attributes = { 252 | LastUpgradeCheck = 0640; 253 | ORGANIZATIONNAME = zhangguobing; 254 | TargetAttributes = { 255 | 84719E1B1B62971A00934D9C = { 256 | CreatedOnToolsVersion = 6.4; 257 | DevelopmentTeam = 4PHWH595B3; 258 | }; 259 | 84719E341B62971A00934D9C = { 260 | CreatedOnToolsVersion = 6.4; 261 | TestTargetID = 84719E1B1B62971A00934D9C; 262 | }; 263 | }; 264 | }; 265 | buildConfigurationList = 84719E171B62971900934D9C /* Build configuration list for PBXProject "微信支付" */; 266 | compatibilityVersion = "Xcode 3.2"; 267 | developmentRegion = English; 268 | hasScannedForEncodings = 0; 269 | knownRegions = ( 270 | en, 271 | Base, 272 | ); 273 | mainGroup = 84719E131B62971900934D9C; 274 | productRefGroup = 84719E1D1B62971A00934D9C /* Products */; 275 | projectDirPath = ""; 276 | projectRoot = ""; 277 | targets = ( 278 | 84719E1B1B62971A00934D9C /* 微信支付 */, 279 | 84719E341B62971A00934D9C /* 微信支付Tests */, 280 | ); 281 | }; 282 | /* End PBXProject section */ 283 | 284 | /* Begin PBXResourcesBuildPhase section */ 285 | 84719E1A1B62971A00934D9C /* Resources */ = { 286 | isa = PBXResourcesBuildPhase; 287 | buildActionMask = 2147483647; 288 | files = ( 289 | 84719E2B1B62971A00934D9C /* Main.storyboard in Resources */, 290 | 84719E301B62971A00934D9C /* LaunchScreen.xib in Resources */, 291 | 84719E2D1B62971A00934D9C /* Images.xcassets in Resources */, 292 | ); 293 | runOnlyForDeploymentPostprocessing = 0; 294 | }; 295 | 84719E331B62971A00934D9C /* Resources */ = { 296 | isa = PBXResourcesBuildPhase; 297 | buildActionMask = 2147483647; 298 | files = ( 299 | ); 300 | runOnlyForDeploymentPostprocessing = 0; 301 | }; 302 | /* End PBXResourcesBuildPhase section */ 303 | 304 | /* Begin PBXSourcesBuildPhase section */ 305 | 84719E181B62971A00934D9C /* Sources */ = { 306 | isa = PBXSourcesBuildPhase; 307 | buildActionMask = 2147483647; 308 | files = ( 309 | 84A622861B6324FD00515D33 /* GBWXPayManager.m in Sources */, 310 | 84A622891B6324FD00515D33 /* WXUtil.mm in Sources */, 311 | 84719E281B62971A00934D9C /* ViewController.m in Sources */, 312 | 84719E251B62971A00934D9C /* AppDelegate.m in Sources */, 313 | 84A622881B6324FD00515D33 /* payRequsestHandler.mm in Sources */, 314 | 84719E221B62971A00934D9C /* main.m in Sources */, 315 | 84A622871B6324FD00515D33 /* ApiXml.mm in Sources */, 316 | ); 317 | runOnlyForDeploymentPostprocessing = 0; 318 | }; 319 | 84719E311B62971A00934D9C /* Sources */ = { 320 | isa = PBXSourcesBuildPhase; 321 | buildActionMask = 2147483647; 322 | files = ( 323 | 84719E3C1B62971A00934D9C /* ____Tests.m in Sources */, 324 | ); 325 | runOnlyForDeploymentPostprocessing = 0; 326 | }; 327 | /* End PBXSourcesBuildPhase section */ 328 | 329 | /* Begin PBXTargetDependency section */ 330 | 84719E371B62971A00934D9C /* PBXTargetDependency */ = { 331 | isa = PBXTargetDependency; 332 | target = 84719E1B1B62971A00934D9C /* 微信支付 */; 333 | targetProxy = 84719E361B62971A00934D9C /* PBXContainerItemProxy */; 334 | }; 335 | /* End PBXTargetDependency section */ 336 | 337 | /* Begin PBXVariantGroup section */ 338 | 84719E291B62971A00934D9C /* Main.storyboard */ = { 339 | isa = PBXVariantGroup; 340 | children = ( 341 | 84719E2A1B62971A00934D9C /* Base */, 342 | ); 343 | name = Main.storyboard; 344 | sourceTree = ""; 345 | }; 346 | 84719E2E1B62971A00934D9C /* LaunchScreen.xib */ = { 347 | isa = PBXVariantGroup; 348 | children = ( 349 | 84719E2F1B62971A00934D9C /* Base */, 350 | ); 351 | name = LaunchScreen.xib; 352 | sourceTree = ""; 353 | }; 354 | /* End PBXVariantGroup section */ 355 | 356 | /* Begin XCBuildConfiguration section */ 357 | 84719E3D1B62971A00934D9C /* Debug */ = { 358 | isa = XCBuildConfiguration; 359 | buildSettings = { 360 | ALWAYS_SEARCH_USER_PATHS = NO; 361 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 362 | CLANG_CXX_LIBRARY = "libc++"; 363 | CLANG_ENABLE_MODULES = YES; 364 | CLANG_ENABLE_OBJC_ARC = YES; 365 | CLANG_WARN_BOOL_CONVERSION = YES; 366 | CLANG_WARN_CONSTANT_CONVERSION = YES; 367 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 368 | CLANG_WARN_EMPTY_BODY = YES; 369 | CLANG_WARN_ENUM_CONVERSION = YES; 370 | CLANG_WARN_INT_CONVERSION = YES; 371 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 372 | CLANG_WARN_UNREACHABLE_CODE = YES; 373 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 374 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 375 | COPY_PHASE_STRIP = NO; 376 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 377 | ENABLE_STRICT_OBJC_MSGSEND = YES; 378 | GCC_C_LANGUAGE_STANDARD = gnu99; 379 | GCC_DYNAMIC_NO_PIC = NO; 380 | GCC_NO_COMMON_BLOCKS = YES; 381 | GCC_OPTIMIZATION_LEVEL = 0; 382 | GCC_PREPROCESSOR_DEFINITIONS = ( 383 | "DEBUG=1", 384 | "$(inherited)", 385 | ); 386 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 387 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 388 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 389 | GCC_WARN_UNDECLARED_SELECTOR = YES; 390 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 391 | GCC_WARN_UNUSED_FUNCTION = YES; 392 | GCC_WARN_UNUSED_VARIABLE = YES; 393 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 394 | MTL_ENABLE_DEBUG_INFO = YES; 395 | ONLY_ACTIVE_ARCH = YES; 396 | SDKROOT = iphoneos; 397 | }; 398 | name = Debug; 399 | }; 400 | 84719E3E1B62971A00934D9C /* Release */ = { 401 | isa = XCBuildConfiguration; 402 | buildSettings = { 403 | ALWAYS_SEARCH_USER_PATHS = NO; 404 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 405 | CLANG_CXX_LIBRARY = "libc++"; 406 | CLANG_ENABLE_MODULES = YES; 407 | CLANG_ENABLE_OBJC_ARC = YES; 408 | CLANG_WARN_BOOL_CONVERSION = YES; 409 | CLANG_WARN_CONSTANT_CONVERSION = YES; 410 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 411 | CLANG_WARN_EMPTY_BODY = YES; 412 | CLANG_WARN_ENUM_CONVERSION = YES; 413 | CLANG_WARN_INT_CONVERSION = YES; 414 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 415 | CLANG_WARN_UNREACHABLE_CODE = YES; 416 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 417 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 418 | COPY_PHASE_STRIP = NO; 419 | DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; 420 | ENABLE_NS_ASSERTIONS = NO; 421 | ENABLE_STRICT_OBJC_MSGSEND = YES; 422 | GCC_C_LANGUAGE_STANDARD = gnu99; 423 | GCC_NO_COMMON_BLOCKS = YES; 424 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 425 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 426 | GCC_WARN_UNDECLARED_SELECTOR = YES; 427 | GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; 428 | GCC_WARN_UNUSED_FUNCTION = YES; 429 | GCC_WARN_UNUSED_VARIABLE = YES; 430 | IPHONEOS_DEPLOYMENT_TARGET = 8.4; 431 | MTL_ENABLE_DEBUG_INFO = NO; 432 | SDKROOT = iphoneos; 433 | VALIDATE_PRODUCT = YES; 434 | }; 435 | name = Release; 436 | }; 437 | 84719E401B62971A00934D9C /* Debug */ = { 438 | isa = XCBuildConfiguration; 439 | buildSettings = { 440 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 441 | CODE_SIGN_IDENTITY = "iPhone Developer"; 442 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 443 | ENABLE_BITCODE = NO; 444 | INFOPLIST_FILE = "微信支付/Info.plist"; 445 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 446 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 447 | LIBRARY_SEARCH_PATHS = ( 448 | "$(inherited)", 449 | "$(PROJECT_DIR)/微信支付/weixinPay/SDKExport", 450 | "$(PROJECT_DIR)/微信支付/WxPay/SDKExport", 451 | "$(PROJECT_DIR)/微信支付/GBWXPay/WxPay/SDKExport", 452 | ); 453 | PRODUCT_NAME = "$(TARGET_NAME)"; 454 | PROVISIONING_PROFILE = "8c91bed8-8849-4d61-89a0-e57dd8b78b48"; 455 | }; 456 | name = Debug; 457 | }; 458 | 84719E411B62971A00934D9C /* Release */ = { 459 | isa = XCBuildConfiguration; 460 | buildSettings = { 461 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 462 | CODE_SIGN_IDENTITY = "iPhone Developer"; 463 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 464 | ENABLE_BITCODE = NO; 465 | INFOPLIST_FILE = "微信支付/Info.plist"; 466 | IPHONEOS_DEPLOYMENT_TARGET = 7.0; 467 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; 468 | LIBRARY_SEARCH_PATHS = ( 469 | "$(inherited)", 470 | "$(PROJECT_DIR)/微信支付/weixinPay/SDKExport", 471 | "$(PROJECT_DIR)/微信支付/WxPay/SDKExport", 472 | "$(PROJECT_DIR)/微信支付/GBWXPay/WxPay/SDKExport", 473 | ); 474 | PRODUCT_NAME = "$(TARGET_NAME)"; 475 | PROVISIONING_PROFILE = "8c91bed8-8849-4d61-89a0-e57dd8b78b48"; 476 | }; 477 | name = Release; 478 | }; 479 | 84719E431B62971A00934D9C /* Debug */ = { 480 | isa = XCBuildConfiguration; 481 | buildSettings = { 482 | BUNDLE_LOADER = "$(TEST_HOST)"; 483 | FRAMEWORK_SEARCH_PATHS = ( 484 | "$(SDKROOT)/Developer/Library/Frameworks", 485 | "$(inherited)", 486 | ); 487 | GCC_PREPROCESSOR_DEFINITIONS = ( 488 | "DEBUG=1", 489 | "$(inherited)", 490 | ); 491 | INFOPLIST_FILE = "微信支付Tests/Info.plist"; 492 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 493 | PRODUCT_NAME = "$(TARGET_NAME)"; 494 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/微信支付.app/微信支付"; 495 | }; 496 | name = Debug; 497 | }; 498 | 84719E441B62971A00934D9C /* Release */ = { 499 | isa = XCBuildConfiguration; 500 | buildSettings = { 501 | BUNDLE_LOADER = "$(TEST_HOST)"; 502 | FRAMEWORK_SEARCH_PATHS = ( 503 | "$(SDKROOT)/Developer/Library/Frameworks", 504 | "$(inherited)", 505 | ); 506 | INFOPLIST_FILE = "微信支付Tests/Info.plist"; 507 | LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; 508 | PRODUCT_NAME = "$(TARGET_NAME)"; 509 | TEST_HOST = "$(BUILT_PRODUCTS_DIR)/微信支付.app/微信支付"; 510 | }; 511 | name = Release; 512 | }; 513 | /* End XCBuildConfiguration section */ 514 | 515 | /* Begin XCConfigurationList section */ 516 | 84719E171B62971900934D9C /* Build configuration list for PBXProject "微信支付" */ = { 517 | isa = XCConfigurationList; 518 | buildConfigurations = ( 519 | 84719E3D1B62971A00934D9C /* Debug */, 520 | 84719E3E1B62971A00934D9C /* Release */, 521 | ); 522 | defaultConfigurationIsVisible = 0; 523 | defaultConfigurationName = Release; 524 | }; 525 | 84719E3F1B62971A00934D9C /* Build configuration list for PBXNativeTarget "微信支付" */ = { 526 | isa = XCConfigurationList; 527 | buildConfigurations = ( 528 | 84719E401B62971A00934D9C /* Debug */, 529 | 84719E411B62971A00934D9C /* Release */, 530 | ); 531 | defaultConfigurationIsVisible = 0; 532 | defaultConfigurationName = Release; 533 | }; 534 | 84719E421B62971A00934D9C /* Build configuration list for PBXNativeTarget "微信支付Tests" */ = { 535 | isa = XCConfigurationList; 536 | buildConfigurations = ( 537 | 84719E431B62971A00934D9C /* Debug */, 538 | 84719E441B62971A00934D9C /* Release */, 539 | ); 540 | defaultConfigurationIsVisible = 0; 541 | defaultConfigurationName = Release; 542 | }; 543 | /* End XCConfigurationList section */ 544 | }; 545 | rootObject = 84719E141B62971900934D9C /* Project object */; 546 | } 547 | -------------------------------------------------------------------------------- /微信支付.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /微信支付.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mokey1422/GBWXPay/8b8590190d83ecab5ac89fe7d97828faf6e54848/微信支付.xcodeproj/project.xcworkspace/xcuserdata/admin.xcuserdatad/UserInterfaceState.xcuserstate -------------------------------------------------------------------------------- /微信支付.xcodeproj/xcuserdata/admin.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist: -------------------------------------------------------------------------------- 1 | 2 | 5 | 6 | -------------------------------------------------------------------------------- /微信支付.xcodeproj/xcuserdata/admin.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | 微信支付.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | 84719E1B1B62971A00934D9C 16 | 17 | primary 18 | 19 | 20 | 84719E341B62971A00934D9C 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /微信支付.xcodeproj/xcuserdata/admin.xcuserdatad/xcschemes/微信支付.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 29 | 35 | 36 | 37 | 38 | 39 | 44 | 45 | 47 | 53 | 54 | 55 | 56 | 57 | 63 | 64 | 65 | 66 | 75 | 77 | 83 | 84 | 85 | 86 | 87 | 88 | 94 | 96 | 102 | 103 | 104 | 105 | 107 | 108 | 111 | 112 | 113 | -------------------------------------------------------------------------------- /微信支付/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // 微信支付 4 | // 5 | // Created by 张国兵 on 15/7/24. 6 | // Copyright (c) 2015年 zhangguobing. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface AppDelegate : UIResponder 12 | 13 | @property (strong, nonatomic) UIWindow *window; 14 | 15 | 16 | @end 17 | 18 | -------------------------------------------------------------------------------- /微信支付/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // 微信支付 4 | // 5 | // Created by 张国兵 on 15/7/24. 6 | // Copyright (c) 2015年 zhangguobing. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "GBWXPayManager.h" 11 | @interface AppDelegate () 12 | 13 | @end 14 | 15 | @implementation AppDelegate 16 | 17 | 18 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 19 | 20 | //向微信注册 21 | [WXApi registerApp:APP_ID withDescription:nil]; 22 | return YES; 23 | } 24 | #pragma mark - 微信支付回调 25 | -(void) onResp:(BaseResp*)resp 26 | { 27 | NSString *strMsg = [NSString stringWithFormat:@"errcode:%d", resp.errCode]; 28 | NSString *strTitle; 29 | 30 | if([resp isKindOfClass:[SendMessageToWXResp class]]) 31 | { 32 | strTitle = [NSString stringWithFormat:@"发送媒体消息结果"]; 33 | } 34 | if([resp isKindOfClass:[PayResp class]]){ 35 | //支付返回结果,实际支付结果需要去微信服务器端查询 36 | strTitle = [NSString stringWithFormat:@"支付结果"]; 37 | 38 | switch (resp.errCode) { 39 | case WXSuccess: 40 | strMsg = @"支付结果:成功!"; 41 | NSLog(@"支付成功-PaySuccess,retcode = %d", resp.errCode); 42 | [[NSNotificationCenter defaultCenter] postNotificationName:@"WXpayresult" object:@"1"]; 43 | break; 44 | 45 | default: 46 | strMsg = [NSString stringWithFormat:@"支付结果:失败!retcode = %d, retstr = %@", resp.errCode,resp.errStr]; 47 | NSLog(@"错误,retcode = %d, retstr = %@", resp.errCode,resp.errStr); 48 | break; 49 | } 50 | } 51 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitle message:strMsg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 52 | [alert show]; 53 | } 54 | 55 | - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 56 | { 57 | return [WXApi handleOpenURL:url delegate:self]; 58 | } 59 | - (void)applicationWillResignActive:(UIApplication *)application { 60 | // Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. 61 | // Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. 62 | } 63 | 64 | - (void)applicationDidEnterBackground:(UIApplication *)application { 65 | // Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later. 66 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits. 67 | } 68 | 69 | - (void)applicationWillEnterForeground:(UIApplication *)application { 70 | // Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background. 71 | } 72 | 73 | - (void)applicationDidBecomeActive:(UIApplication *)application { 74 | // Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. 75 | } 76 | 77 | - (void)applicationWillTerminate:(UIApplication *)application { 78 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:. 79 | } 80 | 81 | @end 82 | -------------------------------------------------------------------------------- /微信支付/Base.lproj/LaunchScreen.xib: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 20 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /微信支付/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | -------------------------------------------------------------------------------- /微信支付/GBWXPay/GBWXPayManager/GBWXPayManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // GBWXPayManager.h 3 | // 微信支付 4 | // 5 | // Created by 张国兵 on 15/7/25. 6 | // Copyright (c) 2015年 zhangguobing. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "GBWXPayManagerConfig.h" 11 | 12 | /** 13 | * 使用说明 14 | *1、直接把GBWXPay文件拖到你的工程里面 15 | *2、配置一下系统库libsqlite3.0.dylib、libz.dzlib、CoreTelephony.framework、SystemConfiguration.frame添加到自己的项目中去,编译一下如果没有问题,就进行下一步,如果有问题可能提示查无此类,不要紧在相应的类里面包含一下#import 就ok了,如果你的pch里面包含了那就更好了这个地方就不会报错 16 | *3、编译无错的话那就在应用的地方包含一下我的管理文件的头文件#import "GBWXPayManager.h",直接调用里面的方法实现支付功能 17 | *4、配置appdelegate,先包含#import "GBWXPayManager.h"头文件,此外注意微信支付调用回调的时候用的时*协议代理,这里要在appdelegate里面包含一下代理协议,复制以下代码: 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 20 | 21 | //向微信注册 22 | [WXApi registerApp:APP_ID withDescription:nil]; 23 | return YES; 24 | } 25 | #pragma mark - 微信支付回调 26 | -(void) onResp:(BaseResp*)resp 27 | { 28 | NSString *strMsg = [NSString stringWithFormat:@"errcode:%d", resp.errCode]; 29 | NSString *strTitle; 30 | 31 | if([resp isKindOfClass:[SendMessageToWXResp class]]) 32 | { 33 | strTitle = [NSString stringWithFormat:@"发送媒体消息结果"]; 34 | } 35 | if([resp isKindOfClass:[PayResp class]]){ 36 | //支付返回结果,实际支付结果需要去微信服务器端查询 37 | strTitle = [NSString stringWithFormat:@"支付结果"]; 38 | 39 | switch (resp.errCode) { 40 | case WXSuccess: 41 | strMsg = @"支付结果:成功!"; 42 | NSLog(@"支付成功-PaySuccess,retcode = %d", resp.errCode); 43 | [[NSNotificationCenter defaultCenter] postNotificationName:@"WXpayresult" object:@"1"]; 44 | break; 45 | 46 | default: 47 | strMsg = [NSString stringWithFormat:@"支付结果:失败!retcode = %d, retstr = %@", resp.errCode,resp.errStr]; 48 | NSLog(@"错误,retcode = %d, retstr = %@", resp.errCode,resp.errStr); 49 | break; 50 | } 51 | } 52 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitle message:strMsg delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil]; 53 | [alert show]; 54 | } 55 | 56 | - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 57 | { 58 | return [WXApi handleOpenURL:url delegate:self]; 59 | } 60 | *5、在实现支付功能的类里面注册监听处理支付成功回调和失败回调,具体看demo 61 | 62 | *6、接下来就要设置回调参数,实现app支付完成的回调了 63 | 点击项目名称,点击“Info”选项卡,在URL types里面添加一项,Identifier可以不填,URL schemes就是appid直接复制进去就ok了; 64 | *7、iOS 9系统策略更新,限制了http协议的访问,此外应用需要在“Info.plist”中将要使用的URL Schemes列为白名单,才可正常检查其他应用是否安装。 65 | * 在“Info.plist”里增加如下代码: 66 | 67 | LSApplicationQueriesSchemes 68 | 69 | weixin 70 | 71 | 72 | NSAppTransportSecurity 73 | 74 | NSAllowsArbitraryLoads 75 | 76 | 77 | *8、解决bitcode编译不过问题 78 | * 在Build Setting将Enable Bitcode 设置为No 79 | */ 80 | 81 | @interface GBWXPayManager : NSObject 82 | /** 83 | * 针对多个商户的支付 84 | * 85 | * @param orderID 支付订单号 86 | * @param orderTitle 订单的商品描述 87 | * @param amount 订单总额 88 | * @param seller 商户号(收款账号) 89 | */ 90 | +(void)wxpayWithOrderID:(NSString*)orderID 91 | orderTitle:(NSString*)orderTitle 92 | amount:(NSString*)amount 93 | sellerID:(NSString *)sellerID 94 | appID:(NSString*)appID 95 | partnerID:(NSString*)partnerID 96 | 97 | ; 98 | 99 | /** 100 | * 单一用户 101 | * 102 | * @param orderID 支付订单号 103 | * @param orderTitle 订单的商品描述 104 | * @param amount 订单总额 105 | */ 106 | +(void)wxpayWithOrderID:(NSString*)orderID 107 | orderTitle:(NSString*)orderTitle 108 | amount:(NSString*)amount; 109 | @end 110 | -------------------------------------------------------------------------------- /微信支付/GBWXPay/GBWXPayManager/GBWXPayManager.m: -------------------------------------------------------------------------------- 1 | // 2 | // GBWXPayManager.m 3 | // 微信支付 4 | // 5 | // Created by 张国兵 on 15/7/25. 6 | // Copyright (c) 2015年 zhangguobing. All rights reserved. 7 | // 8 | 9 | #import "GBWXPayManager.h" 10 | 11 | @implementation GBWXPayManager 12 | /** 13 | * 针对多个商户的支付 14 | * 15 | * @param orderID 支付订单号 16 | * @param orderTitle 订单的商品描述 17 | * @param amount 订单总额 18 | * @param notifyURL 支付结果异步通知 19 | * @param seller 商户号(收款账号) 20 | */ 21 | +(void)wxpayWithOrderID:(NSString*)orderID 22 | orderTitle:(NSString*)orderTitle 23 | amount:(NSString*)amount 24 | sellerID:(NSString *)sellerID 25 | appID:(NSString*)appID 26 | partnerID:(NSString*)partnerID{ 27 | 28 | //微信支付的金额单位是分转化成我们比较常用的'元' 29 | NSString*realPrice=[NSString stringWithFormat:@"%.f",amount.floatValue*100]; 30 | 31 | if(realPrice.floatValue<=0){ 32 | return; 33 | } 34 | //创建支付签名对象 35 | payRequsestHandler *req = [payRequsestHandler alloc]; 36 | //初始化支付签名对象 37 | [req init:appID mch_id:sellerID]; 38 | //设置密钥 39 | [req setKey:partnerID]; 40 | 41 | //获取到实际调起微信支付的参数后,在app端调起支付 42 | NSMutableDictionary *dict = [req sendPay_demo:orderID title:orderTitle price: realPrice]; 43 | 44 | if(dict == nil){ 45 | //错误提示 46 | NSString *debug = [req getDebugifo]; 47 | 48 | [self alert:@"提示信息" msg:debug]; 49 | 50 | NSLog(@"%@\n\n",debug); 51 | }else{ 52 | NSLog(@"%@\n\n",[req getDebugifo]); 53 | 54 | NSMutableString *stamp = [dict objectForKey:@"timestamp"]; 55 | 56 | //调起微信支付 57 | PayReq* req = [[PayReq alloc] init]; 58 | req.openID = [dict objectForKey:@"appid"]; 59 | req.partnerId = [dict objectForKey:@"partnerid"]; 60 | req.prepayId = [dict objectForKey:@"prepayid"]; 61 | req.nonceStr = [dict objectForKey:@"noncestr"]; 62 | req.timeStamp = stamp.intValue; 63 | req.package = [dict objectForKey:@"package"]; 64 | req.sign = [dict objectForKey:@"sign"]; 65 | 66 | BOOL status = [WXApi sendReq:req]; 67 | NSLog(@"%d",status); 68 | 69 | } 70 | 71 | } 72 | /** 73 | * 单一用户 74 | * 75 | * @param orderID 支付订单号 76 | * @param orderTitle 订单的商品描述 77 | * @param amount 订单总额 78 | */ 79 | +(void)wxpayWithOrderID:(NSString*)orderID 80 | orderTitle:(NSString*)orderTitle 81 | amount:(NSString*)amount{ 82 | 83 | 84 | 85 | //微信支付的金额单位是分转化成我们比较常用的'元' 86 | NSString*realPrice=[NSString stringWithFormat:@"%.f",amount.floatValue*100]; 87 | 88 | if(realPrice.floatValue<=0){ 89 | return; 90 | } 91 | //创建支付签名对象 92 | payRequsestHandler *req = [payRequsestHandler alloc]; 93 | //初始化支付签名对象 94 | [req init:APP_ID mch_id:MCH_ID]; 95 | //设置密钥 96 | [req setKey:PARTNER_ID]; 97 | 98 | 99 | 100 | //获取到实际调起微信支付的参数后,在app端调起支付 101 | NSMutableDictionary *dict = [req sendPay_demo:orderID title:orderTitle price: realPrice]; 102 | 103 | if(dict == nil){ 104 | //错误提示 105 | NSString *debug = [req getDebugifo]; 106 | 107 | [self alert:@"提示信息" msg:debug]; 108 | 109 | NSLog(@"%@\n\n",debug); 110 | }else{ 111 | NSLog(@"%@\n\n",[req getDebugifo]); 112 | 113 | NSMutableString *stamp = [dict objectForKey:@"timestamp"]; 114 | 115 | //调起微信支付 116 | PayReq* req = [[PayReq alloc] init]; 117 | req.openID = [dict objectForKey:@"appid"]; 118 | req.partnerId = [dict objectForKey:@"partnerid"]; 119 | req.prepayId = [dict objectForKey:@"prepayid"]; 120 | req.nonceStr = [dict objectForKey:@"noncestr"]; 121 | req.timeStamp = stamp.intValue; 122 | req.package = [dict objectForKey:@"package"]; 123 | req.sign = [dict objectForKey:@"sign"]; 124 | 125 | BOOL status = [WXApi sendReq:req]; 126 | NSLog(@"%d",status); 127 | 128 | } 129 | 130 | 131 | 132 | 133 | } 134 | 135 | 136 | //客户端提示信息 137 | + (void)alert:(NSString *)title msg:(NSString *)msg 138 | { 139 | UIAlertView *alter = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 140 | 141 | [alter show]; 142 | } 143 | @end 144 | -------------------------------------------------------------------------------- /微信支付/GBWXPay/GBWXPayManager/GBWXPayManagerConfig.h: -------------------------------------------------------------------------------- 1 | // 2 | // GBWXPayManagerConfig.h 3 | // 微信支付 4 | // 5 | // Created by 张国兵 on 15/7/25. 6 | // Copyright (c) 2015年 zhangguobing. All rights reserved. 7 | // 8 | 9 | #ifndef _____GBWXPayManagerConfig_h 10 | #define _____GBWXPayManagerConfig_h 11 | //===================== 微信账号帐户资料======================= 12 | 13 | #import "payRequsestHandler.h" //导入微信支付类 14 | #import "WXApi.h" 15 | 16 | #define APP_ID @"wx1adbcf4754b31ba7" //APPID 17 | #define APP_SECRET @"b42e67ad02507810763c0256b1d2fb89" //appsecret 18 | //商户号,填写商户对应参数 19 | #define MCH_ID @"1248267001" 20 | //商户API密钥,填写相应参数 21 | #define PARTNER_ID @"3B689B0104B9D065FAEDDFE320444179" 22 | //支付结果回调页面 23 | #define NOTIFY_URL @"http://wxpay.weixin.qq.com/pub_v2/pay/notify.v2.php" 24 | //获取服务器端支付数据地址(商户自定义) 25 | #define SP_URL @"http://wxpay.weixin.qq.com/pub_v2/app/app_pay.php" 26 | 27 | #endif 28 | -------------------------------------------------------------------------------- /微信支付/GBWXPay/WxPay/SDKExport/WXApi.h: -------------------------------------------------------------------------------- 1 | // 2 | // WXApi.h 3 | // 所有Api接口 4 | // 5 | // Created by Wechat on 12-2-28. 6 | // Copyright (c) 2012年 Tencent. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "WXApiObject.h" 11 | 12 | 13 | #pragma mark - WXApiDelegate 14 | /*! @brief 接收并处理来自微信终端程序的事件消息 15 | * 16 | * 接收并处理来自微信终端程序的事件消息,期间微信界面会切换到第三方应用程序。 17 | * WXApiDelegate 会在handleOpenURL:delegate:中使用并触发。 18 | */ 19 | @protocol WXApiDelegate 20 | @optional 21 | 22 | /*! @brief 收到一个来自微信的请求,第三方应用程序处理完后调用sendResp向微信发送结果 23 | * 24 | * 收到一个来自微信的请求,异步处理完成后必须调用sendResp发送处理结果给微信。 25 | * 可能收到的请求有GetMessageFromWXReq、ShowMessageFromWXReq等。 26 | * @param req 具体请求内容,是自动释放的 27 | */ 28 | -(void) onReq:(BaseReq*)req; 29 | 30 | 31 | 32 | /*! @brief 发送一个sendReq后,收到微信的回应 33 | * 34 | * 收到一个来自微信的处理结果。调用一次sendReq后会收到onResp。 35 | * 可能收到的处理结果有SendMessageToWXResp、SendAuthResp等。 36 | * @param resp具体的回应内容,是自动释放的 37 | */ 38 | -(void) onResp:(BaseResp*)resp; 39 | 40 | @end 41 | 42 | 43 | 44 | #pragma mark - WXApi 45 | 46 | /*! @brief 微信Api接口函数类 47 | * 48 | * 该类封装了微信终端SDK的所有接口 49 | */ 50 | @interface WXApi : NSObject 51 | 52 | /*! @brief WXApi的成员函数,向微信终端程序注册第三方应用。 53 | * 54 | * 需要在每次启动第三方应用程序时调用。第一次调用后,会在微信的可用应用列表中出现。 55 | * iOS7及以上系统需要调起一次微信才会出现在微信的可用应用列表中。 56 | * @attention 请保证在主线程中调用此函数 57 | * @param appid 微信开发者ID 58 | * @return 成功返回YES,失败返回NO。 59 | */ 60 | +(BOOL) registerApp:(NSString *)appid; 61 | 62 | 63 | 64 | /*! @brief WXApi的成员函数,向微信终端程序注册第三方应用。 65 | * 66 | * 需要在每次启动第三方应用程序时调用。第一次调用后,会在微信的可用应用列表中出现。 67 | * @see registerApp 68 | * @param appid 微信开发者ID 69 | * @param appdesc 应用附加信息,长度不超过1024字节 70 | * @return 成功返回YES,失败返回NO。 71 | */ 72 | +(BOOL) registerApp:(NSString *)appid withDescription:(NSString *)appdesc; 73 | 74 | 75 | 76 | /*! @brief 处理微信通过URL启动App时传递的数据 77 | * 78 | * 需要在 application:openURL:sourceApplication:annotation:或者application:handleOpenURL中调用。 79 | * @param url 微信启动第三方应用时传递过来的URL 80 | * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 81 | * @return 成功返回YES,失败返回NO。 82 | */ 83 | +(BOOL) handleOpenURL:(NSURL *) url delegate:(id) delegate; 84 | 85 | 86 | 87 | /*! @brief 检查微信是否已被用户安装 88 | * 89 | * @return 微信已安装返回YES,未安装返回NO。 90 | */ 91 | +(BOOL) isWXAppInstalled; 92 | 93 | 94 | 95 | /*! @brief 判断当前微信的版本是否支持OpenApi 96 | * 97 | * @return 支持返回YES,不支持返回NO。 98 | */ 99 | +(BOOL) isWXAppSupportApi; 100 | 101 | 102 | 103 | /*! @brief 获取微信的itunes安装地址 104 | * 105 | * @return 微信的安装地址字符串。 106 | */ 107 | +(NSString *) getWXAppInstallUrl; 108 | 109 | 110 | 111 | /*! @brief 获取当前微信SDK的版本号 112 | * 113 | * @return 返回当前微信SDK的版本号 114 | */ 115 | +(NSString *) getApiVersion; 116 | 117 | 118 | 119 | /*! @brief 打开微信 120 | * 121 | * @return 成功返回YES,失败返回NO。 122 | */ 123 | +(BOOL) openWXApp; 124 | 125 | 126 | 127 | /*! @brief 发送请求到微信,等待微信返回onResp 128 | * 129 | * 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持以下类型 130 | * SendAuthReq、SendMessageToWXReq、PayReq等。 131 | * @param req 具体的发送请求,在调用函数后,请自己释放。 132 | * @return 成功返回YES,失败返回NO。 133 | */ 134 | +(BOOL) sendReq:(BaseReq*)req; 135 | 136 | /*! @brief 发送Auth请求到微信,支持用户没安装微信,等待微信返回onResp 137 | * 138 | * 函数调用后,会切换到微信的界面。第三方应用程序等待微信返回onResp。微信在异步处理完成后一定会调用onResp。支持SendAuthReq类型。 139 | * @param req 具体的发送请求,在调用函数后,请自己释放。 140 | * @param viewController 当前界面对象。 141 | * @param delegate WXApiDelegate对象,用来接收微信触发的消息。 142 | * @return 成功返回YES,失败返回NO。 143 | */ 144 | +(BOOL) sendAuthReq:(SendAuthReq*) req viewController : (UIViewController*) viewController delegate:(id) delegate; 145 | 146 | 147 | /*! @brief 收到微信onReq的请求,发送对应的应答给微信,并切换到微信界面 148 | * 149 | * 函数调用后,会切换到微信的界面。第三方应用程序收到微信onReq的请求,异步处理该请求,完成后必须调用该函数。可能发送的相应有 150 | * GetMessageFromWXResp、ShowMessageFromWXResp等。 151 | * @param resp 具体的应答内容,调用函数后,请自己释放 152 | * @return 成功返回YES,失败返回NO。 153 | */ 154 | +(BOOL) sendResp:(BaseResp*)resp; 155 | 156 | 157 | @end 158 | -------------------------------------------------------------------------------- /微信支付/GBWXPay/WxPay/SDKExport/WXApiObject.h: -------------------------------------------------------------------------------- 1 | // 2 | // MMApiObject.h 3 | // Api对象,包含所有接口和对象数据定义 4 | // 5 | // Created by Wechat on 12-2-28. 6 | // Copyright (c) 2012年 Tencent. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | /*! @brief 错误码 13 | * 14 | */ 15 | enum WXErrCode { 16 | WXSuccess = 0, /**< 成功 */ 17 | WXErrCodeCommon = -1, /**< 普通错误类型 */ 18 | WXErrCodeUserCancel = -2, /**< 用户点击取消并返回 */ 19 | WXErrCodeSentFail = -3, /**< 发送失败 */ 20 | WXErrCodeAuthDeny = -4, /**< 授权失败 */ 21 | WXErrCodeUnsupport = -5, /**< 微信不支持 */ 22 | }; 23 | 24 | 25 | 26 | /*! @brief 请求发送场景 27 | * 28 | */ 29 | enum WXScene { 30 | WXSceneSession = 0, /**< 聊天界面 */ 31 | WXSceneTimeline = 1, /**< 朋友圈 */ 32 | WXSceneFavorite = 2, /**< 收藏 */ 33 | }; 34 | 35 | 36 | 37 | enum WXAPISupport { 38 | WXAPISupportSession = 0, 39 | }; 40 | 41 | 42 | 43 | /*! @brief 跳转profile类型 44 | * 45 | */ 46 | enum WXBizProfileType{ 47 | WXBizProfileType_Normal = 0, //**< 普通公众号 */ 48 | WXBizProfileType_Device = 1, //**< 硬件公众号 */ 49 | }; 50 | 51 | 52 | 53 | /*! @brief 跳转mp网页类型 54 | * 55 | */ 56 | enum WXMPWebviewType { 57 | WXMPWebviewType_Ad = 0, /**< 广告网页 **/ 58 | }; 59 | 60 | #pragma mark - BaseReq 61 | /*! @brief 该类为微信终端SDK所有请求类的基类 62 | * 63 | */ 64 | @interface BaseReq : NSObject 65 | 66 | /** 请求类型 */ 67 | @property (nonatomic, assign) int type; 68 | /** 由用户微信号和AppID组成的唯一标识,发送请求时第三方程序必须填写,用于校验微信用户是否换号登录*/ 69 | @property (nonatomic, retain) NSString* openID; 70 | 71 | @end 72 | 73 | 74 | 75 | #pragma mark - BaseResp 76 | /*! @brief 该类为微信终端SDK所有响应类的基类 77 | * 78 | */ 79 | @interface BaseResp : NSObject 80 | /** 错误码 */ 81 | @property (nonatomic, assign) int errCode; 82 | /** 错误提示字符串 */ 83 | @property (nonatomic, retain) NSString *errStr; 84 | /** 响应类型 */ 85 | @property (nonatomic, assign) int type; 86 | 87 | @end 88 | 89 | 90 | 91 | #pragma mark - WXMediaMessage 92 | @class WXMediaMessage; 93 | 94 | /*! @brief 第三方向微信终端发起支付的消息结构体 95 | * 96 | * 第三方向微信终端发起支付的消息结构体,微信终端处理后会向第三方返回处理结果 97 | * @see PayResp 98 | */ 99 | @interface PayReq : BaseReq 100 | 101 | /** 商家向财付通申请的商家id */ 102 | @property (nonatomic, retain) NSString *partnerId; 103 | /** 预支付订单 */ 104 | @property (nonatomic, retain) NSString *prepayId; 105 | /** 随机串,防重发 */ 106 | @property (nonatomic, retain) NSString *nonceStr; 107 | /** 时间戳,防重发 */ 108 | @property (nonatomic, assign) UInt32 timeStamp; 109 | /** 商家根据财付通文档填写的数据和签名 */ 110 | @property (nonatomic, retain) NSString *package; 111 | /** 商家根据微信开放平台文档对数据做的签名 */ 112 | @property (nonatomic, retain) NSString *sign; 113 | 114 | @end 115 | 116 | 117 | 118 | #pragma mark - PayResp 119 | /*! @brief 微信终端返回给第三方的关于支付结果的结构体 120 | * 121 | * 微信终端返回给第三方的关于支付结果的结构体 122 | */ 123 | @interface PayResp : BaseResp 124 | 125 | /** 财付通返回给商家的信息 */ 126 | @property (nonatomic, retain) NSString *returnKey; 127 | 128 | @end 129 | 130 | 131 | 132 | #pragma mark - SendAuthReq 133 | /*! @brief 第三方程序向微信终端请求认证的消息结构 134 | * 135 | * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数, 136 | * 向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 137 | * @see SendAuthResp 138 | */ 139 | @interface SendAuthReq : BaseReq 140 | /** 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 141 | * @see SendAuthResp 142 | * @note scope字符串长度不能超过1K 143 | */ 144 | @property (nonatomic, retain) NSString* scope; 145 | /** 第三方程序本身用来标识其请求的唯一性,最后跳转回第三方程序时,由微信终端回传。 146 | * @note state字符串长度不能超过1K 147 | */ 148 | @property (nonatomic, retain) NSString* state; 149 | @end 150 | 151 | 152 | 153 | #pragma mark - SendAuthResp 154 | /*! @brief 微信处理完第三方程序的认证和权限申请后向第三方程序回送的处理结果。 155 | * 156 | * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。 157 | * 微信终端处理完后会向第三方程序发送一个SendAuthResp。 158 | * @see onResp 159 | */ 160 | @interface SendAuthResp : BaseResp 161 | @property (nonatomic, retain) NSString* code; 162 | /** 第三方程序发送时用来标识其请求的唯一性的标志,由第三方程序调用sendReq时传入,由微信终端回传 163 | * @note state字符串长度不能超过1K 164 | */ 165 | @property (nonatomic, retain) NSString* state; 166 | @property (nonatomic, retain) NSString* lang; 167 | @property (nonatomic, retain) NSString* country; 168 | @end 169 | 170 | 171 | 172 | #pragma mark - SendMessageToWXReq 173 | /*! @brief 第三方程序发送消息至微信终端程序的消息结构体 174 | * 175 | * 第三方程序向微信发送信息需要传入SendMessageToWXReq结构体,信息类型包括文本消息和多媒体消息, 176 | * 分别对应于text和message成员。调用该方法后,微信处理完信息会向第三方程序发送一个处理结果。 177 | * @see SendMessageToWXResp 178 | */ 179 | @interface SendMessageToWXReq : BaseReq 180 | /** 发送消息的文本内容 181 | * @note 文本长度必须大于0且小于10K 182 | */ 183 | @property (nonatomic, retain) NSString* text; 184 | /** 发送消息的多媒体内容 185 | * @see WXMediaMessage 186 | */ 187 | @property (nonatomic, retain) WXMediaMessage* message; 188 | /** 发送消息的类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ 189 | @property (nonatomic, assign) BOOL bText; 190 | /** 发送的目标场景,可以选择发送到会话(WXSceneSession)或者朋友圈(WXSceneTimeline)。 默认发送到会话。 191 | * @see WXScene 192 | */ 193 | @property (nonatomic, assign) int scene; 194 | 195 | @end 196 | 197 | 198 | 199 | #pragma mark - SendMessageToWXResp 200 | /*! @brief 微信终端向第三方程序返回的SendMessageToWXReq处理结果。 201 | * 202 | * 第三方程序向微信终端发送SendMessageToWXReq后,微信发送回来的处理结果,该结果用SendMessageToWXResp表示。 203 | */ 204 | @interface SendMessageToWXResp : BaseResp 205 | @property(nonatomic, retain) NSString* lang; 206 | @property(nonatomic, retain) NSString* country; 207 | @end 208 | 209 | 210 | #pragma mark - GetMessageFromWXReq 211 | /*! @brief 微信终端向第三方程序请求提供内容的消息结构体。 212 | * 213 | * 微信终端向第三方程序请求提供内容,微信终端会向第三方程序发送GetMessageFromWXReq消息结构体, 214 | * 需要第三方程序调用sendResp返回一个GetMessageFromWXResp消息结构体。 215 | */ 216 | @interface GetMessageFromWXReq : BaseReq 217 | @property (nonatomic, retain) NSString* lang; 218 | @property (nonatomic, retain) NSString* country; 219 | @end 220 | 221 | 222 | 223 | #pragma mark - GetMessageFromWXResp 224 | /*! @brief 微信终端向第三方程序请求提供内容,第三方程序向微信终端返回的消息结构体。 225 | * 226 | * 微信终端向第三方程序请求提供内容,第三方程序调用sendResp向微信终端返回一个GetMessageFromWXResp消息结构体。 227 | */ 228 | @interface GetMessageFromWXResp : BaseResp 229 | /** 向微信终端提供的文本内容 230 | @note 文本长度必须大于0且小于10K 231 | */ 232 | @property (nonatomic, retain) NSString* text; 233 | /** 向微信终端提供的多媒体内容。 234 | * @see WXMediaMessage 235 | */ 236 | @property (nonatomic, retain) WXMediaMessage* message; 237 | /** 向微信终端提供内容的消息类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ 238 | @property (nonatomic, assign) BOOL bText; 239 | @end 240 | 241 | 242 | 243 | #pragma mark - ShowMessageFromWXReq 244 | /*! @brief 微信通知第三方程序,要求第三方程序显示的消息结构体。 245 | * 246 | * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 247 | * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 248 | */ 249 | @interface ShowMessageFromWXReq : BaseReq 250 | /** 微信终端向第三方程序发送的要求第三方程序处理的多媒体内容 251 | * @see WXMediaMessage 252 | */ 253 | @property (nonatomic, retain) WXMediaMessage* message; 254 | @property (nonatomic, retain) NSString* lang; 255 | @property (nonatomic, retain) NSString* country; 256 | @end 257 | 258 | 259 | 260 | #pragma mark - ShowMessageFromWXResp 261 | /*! @brief 微信通知第三方程序,要求第三方程序显示或处理某些消息,第三方程序处理完后向微信终端发送的处理结果。 262 | * 263 | * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 264 | * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 265 | */ 266 | @interface ShowMessageFromWXResp : BaseResp 267 | @end 268 | 269 | 270 | 271 | #pragma mark - LaunchFromWXReq 272 | /*! @brief 微信终端打开第三方程序携带的消息结构体 273 | * 274 | * 微信向第三方发送的结构体,第三方不需要返回 275 | */ 276 | @interface LaunchFromWXReq : BaseReq 277 | @property (nonatomic, retain) WXMediaMessage* message; 278 | @property (nonatomic, retain) NSString* lang; 279 | @property (nonatomic, retain) NSString* country; 280 | @end 281 | 282 | 283 | #pragma mark - OpenTempSessionReq 284 | /* ! @brief 第三方通知微信,打开临时会话 285 | * 286 | * 第三方通知微信,打开临时会话 287 | */ 288 | @interface OpenTempSessionReq : BaseReq 289 | /** 需要打开的用户名 290 | * @attention 长度不能超过512字节 291 | */ 292 | @property (nonatomic, retain) NSString* username; 293 | /** 开发者自定义参数,拉起临时会话后会发给开发者后台,可以用于识别场景 294 | * @attention 长度不能超过32位 295 | */ 296 | @property (nonatomic, retain) NSString* sessionFrom; 297 | @end 298 | 299 | #pragma mark - OpenTempSessionResp 300 | /*! @brief 微信终端向第三方程序返回的OpenTempSessionReq处理结果。 301 | * 302 | * 第三方程序向微信终端发送OpenTempSessionReq后,微信发送回来的处理结果,该结果用OpenTempSessionResp表示。 303 | */ 304 | @interface OpenTempSessionResp : BaseResp 305 | 306 | @end 307 | 308 | #pragma mark - OpenWebviewReq 309 | /* ! @brief 第三方通知微信启动内部浏览器,打开指定网页 310 | * 311 | * 第三方通知微信启动内部浏览器,打开指定Url对应的网页 312 | */ 313 | @interface OpenWebviewReq : BaseReq 314 | /** 需要打开的网页对应的Url 315 | * @attention 长度不能超过1024 316 | */ 317 | @property(nonatomic,retain)NSString* url; 318 | 319 | @end 320 | 321 | #pragma mark - OpenWebviewResp 322 | /*! @brief 微信终端向第三方程序返回的OpenWebviewReq处理结果 323 | * 324 | * 第三方程序向微信终端发送OpenWebviewReq后,微信发送回来的处理结果,该结果用OpenWebviewResp表示 325 | */ 326 | @interface OpenWebviewResp : BaseResp 327 | 328 | @end 329 | 330 | #pragma mark - OpenRankListReq 331 | /* ! @brief 第三方通知微信,打开硬件排行榜 332 | * 333 | * 第三方通知微信,打开硬件排行榜 334 | */ 335 | @interface OpenRankListReq : BaseReq 336 | 337 | @end 338 | 339 | #pragma mark - OpenRanklistResp 340 | /*! @brief 微信终端向第三方程序返回的OpenRankListReq处理结果。 341 | * 342 | * 第三方程序向微信终端发送OpenRankListReq后,微信发送回来的处理结果,该结果用OpenRankListResp表示。 343 | */ 344 | @interface OpenRankListResp : BaseResp 345 | 346 | @end 347 | 348 | 349 | #pragma mark - JumpToBizProfileReq 350 | /* ! @brief 第三方通知微信,打开指定微信号profile页面 351 | * 352 | * 第三方通知微信,打开指定微信号profile页面 353 | */ 354 | @interface JumpToBizProfileReq : BaseReq 355 | /** 跳转到该公众号的profile 356 | * @attention 长度不能超过512字节 357 | */ 358 | @property (nonatomic, retain) NSString* username; 359 | /** 如果用户加了该公众号为好友,extMsg会上传到服务器 360 | * @attention 长度不能超过1024字节 361 | */ 362 | @property (nonatomic, retain) NSString* extMsg; 363 | /** 364 | * 跳转的公众号类型 365 | * @see WXBizProfileType 366 | */ 367 | @property (nonatomic, assign) int profileType; 368 | @end 369 | 370 | 371 | 372 | #pragma mark - JumpToBizWebviewReq 373 | /* ! @brief 第三方通知微信,打开指定usrname的profile网页版 374 | * 375 | */ 376 | @interface JumpToBizWebviewReq : BaseReq 377 | /** 跳转的网页类型,目前只支持广告页 378 | * @see WXMPWebviewType 379 | */ 380 | @property(nonatomic, assign) int webType; 381 | /** 跳转到该公众号的profile网页版 382 | * @attention 长度不能超过512字节 383 | */ 384 | @property(nonatomic, retain) NSString* tousrname; 385 | /** 如果用户加了该公众号为好友,extMsg会上传到服务器 386 | * @attention 长度不能超过1024字节 387 | */ 388 | @property(nonatomic, retain) NSString* extMsg; 389 | 390 | @end 391 | 392 | #pragma mark - WXCardItem 393 | 394 | @interface WXCardItem : NSObject 395 | /** 卡id 396 | * @attention 长度不能超过1024字节 397 | */ 398 | @property (nonatomic,retain) NSString* cardId; 399 | /** ext信息 400 | * @attention 长度不能超过2024字节 401 | 402 | * 具体见http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html#.E9.99.84.E5.BD.954-.E5.8D.A1.E5.88.B8.E6.89.A9.E5.B1.95.E5.AD.97.E6.AE.B5.E5.8F.8A.E7.AD.BE.E5.90.8D.E7.94.9F.E6.88.90.E7.AE.97.E6.B3.95 卡券扩展字段cardExt说明 403 | 404 | 405 | */ 406 | @property (nonatomic,retain) NSString* extMsg; 407 | /** 408 | * @attention 卡的状态,req不需要填。resp:0为未添加,1为已添加。 409 | */ 410 | @property (nonatomic,assign) UInt32 cardState; 411 | @end; 412 | 413 | #pragma mark - AddCardToWXCardPackageReq 414 | /* ! @brief 请求添加卡券至微信卡包 415 | * 416 | */ 417 | 418 | @interface AddCardToWXCardPackageReq : BaseReq 419 | /** 卡列表 420 | * @attention 个数不能超过40个 类型WXCardItem 421 | */ 422 | @property (nonatomic,retain) NSArray* cardAry; 423 | 424 | @end 425 | 426 | 427 | #pragma mark - AddCardToWXCardPackageResp 428 | /** ! @brief 微信返回第三方添加卡券结果 429 | * 430 | */ 431 | 432 | @interface AddCardToWXCardPackageResp : BaseResp 433 | /** 卡列表 434 | * @attention 个数不能超过40个 类型WXCardItem 435 | */ 436 | @property (nonatomic,retain) NSArray* cardAry; 437 | @end 438 | 439 | 440 | #pragma mark - WXMediaMessage 441 | 442 | /*! @brief 多媒体消息结构体 443 | * 444 | * 用于微信终端和第三方程序之间传递消息的多媒体消息内容 445 | */ 446 | @interface WXMediaMessage : NSObject 447 | 448 | +(WXMediaMessage *) message; 449 | 450 | /** 标题 451 | * @note 长度不能超过512字节 452 | */ 453 | @property (nonatomic, retain) NSString *title; 454 | /** 描述内容 455 | * @note 长度不能超过1K 456 | */ 457 | @property (nonatomic, retain) NSString *description; 458 | /** 缩略图数据 459 | * @note 大小不能超过32K 460 | */ 461 | @property (nonatomic, retain) NSData *thumbData; 462 | /** 463 | * @note 长度不能超过64字节 464 | */ 465 | @property (nonatomic, retain) NSString *mediaTagName; 466 | /** 467 | * 468 | */ 469 | @property (nonatomic, retain) NSString *messageExt; 470 | @property (nonatomic, retain) NSString *messageAction; 471 | /** 472 | * 多媒体数据对象,可以为WXImageObject,WXMusicObject,WXVideoObject,WXWebpageObject等。 473 | */ 474 | @property (nonatomic, retain) id mediaObject; 475 | 476 | /*! @brief 设置消息缩略图的方法 477 | * 478 | * @param image 缩略图 479 | * @note 大小不能超过32K 480 | */ 481 | - (void) setThumbImage:(UIImage *)image; 482 | 483 | @end 484 | 485 | 486 | 487 | #pragma mark - WXImageObject 488 | /*! @brief 多媒体消息中包含的图片数据对象 489 | * 490 | * 微信终端和第三方程序之间传递消息中包含的图片数据对象。 491 | * @note imageData和imageUrl成员不能同时为空 492 | * @see WXMediaMessage 493 | */ 494 | @interface WXImageObject : NSObject 495 | /*! @brief 返回一个WXImageObject对象 496 | * 497 | * @note 返回的WXImageObject对象是自动释放的 498 | */ 499 | +(WXImageObject *) object; 500 | 501 | /** 图片真实数据内容 502 | * @note 大小不能超过10M 503 | */ 504 | @property (nonatomic, retain) NSData *imageData; 505 | /** 图片url 506 | * @note 长度不能超过10K 507 | */ 508 | @property (nonatomic, retain) NSString *imageUrl; 509 | 510 | @end 511 | 512 | 513 | #pragma mark - WXMusicObject 514 | /*! @brief 多媒体消息中包含的音乐数据对象 515 | * 516 | * 微信终端和第三方程序之间传递消息中包含的音乐数据对象。 517 | * @note musicUrl和musicLowBandUrl成员不能同时为空。 518 | * @see WXMediaMessage 519 | */ 520 | @interface WXMusicObject : NSObject 521 | /*! @brief 返回一个WXMusicObject对象 522 | * 523 | * @note 返回的WXMusicObject对象是自动释放的 524 | */ 525 | +(WXMusicObject *) object; 526 | 527 | /** 音乐网页的url地址 528 | * @note 长度不能超过10K 529 | */ 530 | @property (nonatomic, retain) NSString *musicUrl; 531 | /** 音乐lowband网页的url地址 532 | * @note 长度不能超过10K 533 | */ 534 | @property (nonatomic, retain) NSString *musicLowBandUrl; 535 | /** 音乐数据url地址 536 | * @note 长度不能超过10K 537 | */ 538 | @property (nonatomic, retain) NSString *musicDataUrl; 539 | 540 | /**音乐lowband数据url地址 541 | * @note 长度不能超过10K 542 | */ 543 | @property (nonatomic, retain) NSString *musicLowBandDataUrl; 544 | 545 | @end 546 | 547 | 548 | 549 | #pragma mark - WXVideoObject 550 | /*! @brief 多媒体消息中包含的视频数据对象 551 | * 552 | * 微信终端和第三方程序之间传递消息中包含的视频数据对象。 553 | * @note videoUrl和videoLowBandUrl不能同时为空。 554 | * @see WXMediaMessage 555 | */ 556 | @interface WXVideoObject : NSObject 557 | /*! @brief 返回一个WXVideoObject对象 558 | * 559 | * @note 返回的WXVideoObject对象是自动释放的 560 | */ 561 | +(WXVideoObject *) object; 562 | 563 | /** 视频网页的url地址 564 | * @note 长度不能超过10K 565 | */ 566 | @property (nonatomic, retain) NSString *videoUrl; 567 | /** 视频lowband网页的url地址 568 | * @note 长度不能超过10K 569 | */ 570 | @property (nonatomic, retain) NSString *videoLowBandUrl; 571 | 572 | @end 573 | 574 | 575 | 576 | #pragma mark - WXWebpageObject 577 | /*! @brief 多媒体消息中包含的网页数据对象 578 | * 579 | * 微信终端和第三方程序之间传递消息中包含的网页数据对象。 580 | * @see WXMediaMessage 581 | */ 582 | @interface WXWebpageObject : NSObject 583 | /*! @brief 返回一个WXWebpageObject对象 584 | * 585 | * @note 返回的WXWebpageObject对象是自动释放的 586 | */ 587 | +(WXWebpageObject *) object; 588 | 589 | /** 网页的url地址 590 | * @note 不能为空且长度不能超过10K 591 | */ 592 | @property (nonatomic, retain) NSString *webpageUrl; 593 | 594 | @end 595 | 596 | 597 | 598 | #pragma mark - WXAppExtendObject 599 | /*! @brief 多媒体消息中包含的App扩展数据对象 600 | * 601 | * 第三方程序向微信终端发送包含WXAppExtendObject的多媒体消息, 602 | * 微信需要处理该消息时,会调用该第三方程序来处理多媒体消息内容。 603 | * @note url,extInfo和fileData不能同时为空 604 | * @see WXMediaMessage 605 | */ 606 | @interface WXAppExtendObject : NSObject 607 | /*! @brief 返回一个WXAppExtendObject对象 608 | * 609 | * @note 返回的WXAppExtendObject对象是自动释放的 610 | */ 611 | +(WXAppExtendObject *) object; 612 | 613 | /** 若第三方程序不存在,微信终端会打开该url所指的App下载地址 614 | * @note 长度不能超过10K 615 | */ 616 | @property (nonatomic, retain) NSString *url; 617 | /** 第三方程序自定义简单数据,微信终端会回传给第三方程序处理 618 | * @note 长度不能超过2K 619 | */ 620 | @property (nonatomic, retain) NSString *extInfo; 621 | /** App文件数据,该数据发送给微信好友,微信好友需要点击后下载数据,微信终端会回传给第三方程序处理 622 | * @note 大小不能超过10M 623 | */ 624 | @property (nonatomic, retain) NSData *fileData; 625 | 626 | @end 627 | 628 | 629 | 630 | #pragma mark - WXEmoticonObject 631 | /*! @brief 多媒体消息中包含的表情数据对象 632 | * 633 | * 微信终端和第三方程序之间传递消息中包含的表情数据对象。 634 | * @see WXMediaMessage 635 | */ 636 | @interface WXEmoticonObject : NSObject 637 | 638 | /*! @brief 返回一个WXEmoticonObject对象 639 | * 640 | * @note 返回的WXEmoticonObject对象是自动释放的 641 | */ 642 | +(WXEmoticonObject *) object; 643 | 644 | /** 表情真实数据内容 645 | * @note 大小不能超过10M 646 | */ 647 | @property (nonatomic, retain) NSData *emoticonData; 648 | 649 | @end 650 | 651 | 652 | 653 | #pragma mark - WXFileObject 654 | /*! @brief 多媒体消息中包含的文件数据对象 655 | * 656 | * @see WXMediaMessage 657 | */ 658 | @interface WXFileObject : NSObject 659 | 660 | /*! @brief 返回一个WXFileObject对象 661 | * 662 | * @note 返回的WXFileObject对象是自动释放的 663 | */ 664 | +(WXFileObject *) object; 665 | 666 | /** 文件后缀名 667 | * @note 长度不超过64字节 668 | */ 669 | @property (nonatomic, retain) NSString *fileExtension; 670 | 671 | /** 文件真实数据内容 672 | * @note 大小不能超过10M 673 | */ 674 | @property (nonatomic, retain) NSData *fileData; 675 | 676 | @end 677 | -------------------------------------------------------------------------------- /微信支付/GBWXPay/WxPay/SDKExport/libWeChatSDK.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mokey1422/GBWXPay/8b8590190d83ecab5ac89fe7d97828faf6e54848/微信支付/GBWXPay/WxPay/SDKExport/libWeChatSDK.a -------------------------------------------------------------------------------- /微信支付/GBWXPay/WxPay/lib/ApiXml.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #import 4 | /* 5 | XML 解析库api说明: 6 | //============================================================================ 7 | 8 | //输入参数为xml格式串,初始化解析器 9 | -(void)startParse:(NSData *)data; 10 | 11 | //获取解析后的字典 12 | -(NSMutableDictionary*) getDict; 13 | 14 | //============================================================================ 15 | */ 16 | @interface XMLHelper : NSObject { 17 | 18 | //解析器 19 | NSXMLParser *xmlParser; 20 | //解析元素 21 | NSMutableArray *xmlElements; 22 | //解析结果 23 | NSMutableDictionary *dictionary; 24 | //临时串变量 25 | NSMutableString *contentString; 26 | } 27 | //输入参数为xml格式串,初始化解析器 28 | -(void)startParse:(NSData *)data; 29 | //获取解析后的字典 30 | -(NSMutableDictionary*) getDict; 31 | @end 32 | -------------------------------------------------------------------------------- /微信支付/GBWXPay/WxPay/lib/ApiXml.mm: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | #import "ApiXml.h" 4 | /* 5 | XML 解析库 6 | */ 7 | @implementation XMLHelper 8 | -(void) startParse:(NSData *)data{ 9 | 10 | dictionary =[NSMutableDictionary dictionary]; 11 | contentString=[NSMutableString string]; 12 | 13 | //Demo XML解析实例 14 | xmlElements = [[NSMutableArray alloc] init]; 15 | 16 | xmlParser = [[NSXMLParser alloc] initWithData:data]; 17 | 18 | [xmlParser setDelegate:self]; 19 | [xmlParser parse]; 20 | 21 | } 22 | -(NSMutableDictionary*) getDict{ 23 | return dictionary; 24 | } 25 | //解析文档开始 26 | - (void)parserDidStartDocument:(NSXMLParser *)parser{ 27 | //NSLog(@"解析文档开始"); 28 | } 29 | - (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{ 30 | //NSLog(@"遇到启始标签:%@",elementName); 31 | } 32 | 33 | - (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{ 34 | //NSLog(@"遇到内容:%@",string); 35 | [contentString setString:string]; 36 | } 37 | 38 | - (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{ 39 | //NSLog(@"遇到结束标签:%@",elementName); 40 | 41 | if( ![contentString isEqualToString:@"\n"] && ![elementName isEqualToString:@"root"]){ 42 | [dictionary setObject: [contentString copy] forKey:elementName]; 43 | //NSLog(@"%@=%@",elementName, contentString); 44 | } 45 | } 46 | 47 | //解析文档结束 48 | - (void)parserDidEndDocument:(NSXMLParser *)parser{ 49 | 50 | 51 | } 52 | 53 | @end -------------------------------------------------------------------------------- /微信支付/GBWXPay/WxPay/lib/WXUtil.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #import 4 | #import 5 | 6 | @interface WXUtil :NSObject 7 | { 8 | } 9 | /* 10 | 加密实现MD5和SHA1 11 | */ 12 | +(NSString *) md5:(NSString *)str; 13 | +(NSString*) sha1:(NSString *)str; 14 | /** 15 | 实现http GET/POST 解析返回的json数据 16 | */ 17 | +(NSData *) httpSend:(NSString *)url method:(NSString *)method data:(NSString *)data; 18 | @end -------------------------------------------------------------------------------- /微信支付/GBWXPay/WxPay/lib/WXUtil.mm: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | #import "WXUtil.h" 4 | /* 5 | 加密实现MD5和SHA1 6 | */ 7 | @implementation WXUtil 8 | 9 | //md5 encode 10 | +(NSString *) md5:(NSString *)str 11 | { 12 | const char *cStr = [str UTF8String]; 13 | unsigned char digest[CC_MD5_DIGEST_LENGTH]; 14 | CC_MD5( cStr, (unsigned int)strlen(cStr), digest ); 15 | 16 | NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; 17 | 18 | for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) 19 | [output appendFormat:@"%02X", digest[i]]; 20 | 21 | return output; 22 | } 23 | //sha1 encode 24 | +(NSString*) sha1:(NSString *)str 25 | { 26 | const char *cstr = [str cStringUsingEncoding:NSUTF8StringEncoding]; 27 | NSData *data = [NSData dataWithBytes:cstr length:str.length]; 28 | 29 | uint8_t digest[CC_SHA1_DIGEST_LENGTH]; 30 | 31 | CC_SHA1(data.bytes, (unsigned int)data.length, digest); 32 | 33 | NSMutableString* output = [NSMutableString stringWithCapacity:CC_SHA1_DIGEST_LENGTH * 2]; 34 | 35 | for(int i = 0; i < CC_SHA1_DIGEST_LENGTH; i++) 36 | [output appendFormat:@"%02x", digest[i]]; 37 | 38 | return output; 39 | } 40 | //http 请求 41 | +(NSData *) httpSend:(NSString *)url method:(NSString *)method data:(NSString *)data 42 | { 43 | NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:5]; 44 | //设置提交方式 45 | [request setHTTPMethod:method]; 46 | //设置数据类型 47 | [request addValue:@"text/xml" forHTTPHeaderField:@"Content-Type"]; 48 | //设置编码 49 | [request setValue:@"UTF-8" forHTTPHeaderField:@"charset"]; 50 | //如果是POST 51 | [request setHTTPBody:[data dataUsingEncoding:NSUTF8StringEncoding]]; 52 | 53 | NSError *error; 54 | //将请求的url数据放到NSData对象中 55 | NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error]; 56 | return response; 57 | //return [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding]; 58 | } 59 | 60 | @end -------------------------------------------------------------------------------- /微信支付/GBWXPay/WxPay/lib/payRequsestHandler.h: -------------------------------------------------------------------------------- 1 | 2 | 3 | #import 4 | #import "WXUtil.h" 5 | #import "ApiXml.h" 6 | /* 7 | // 签名实例 8 | // 更新时间:2015年3月3日 9 | // 负责人:李启波(marcyli) 10 | // 该Demo用于ios sdk 1.4 11 | 12 | //微信支付服务器签名支付请求请求类 13 | //============================================================================ 14 | //api说明: 15 | //初始化商户参数,默认给一些参数赋值,如cmdno,date等。 16 | -(BOOL) init:(NSString *)app_id (NSString *)mch_id; 17 | 18 | //设置商户API密钥 19 | -(void) setKey:(NSString *)key; 20 | 21 | //生成签名 22 | -(NSString*) createMd5Sign:(NSMutableDictionary*)dict; 23 | 24 | //获取XML格式的数据 25 | -(NSString *) genPackage:(NSMutableDictionary*)packageParams; 26 | 27 | //提交预支付交易,获取预支付交易会话标识 28 | -(NSString *) sendPrepay:(NSMutableDictionary *); 29 | 30 | //签名实例测试 31 | - ( NSMutableDictionary *)sendPay_demo; 32 | 33 | //获取debug信息日志 34 | -(NSString *) getDebugifo; 35 | 36 | //获取最后返回的错误代码 37 | -(long) getLasterrCode; 38 | //============================================================================ 39 | */ 40 | 41 | // 账号帐户资料 42 | //更改商户把相关参数后可测试 43 | 44 | 45 | @interface payRequsestHandler : NSObject{ 46 | //预支付网关url地址 47 | NSString *payUrl; 48 | 49 | //lash_errcode; 50 | long last_errcode; 51 | //debug信息 52 | NSMutableString *debugInfo; 53 | NSString *appid,*mchid,*spkey; 54 | } 55 | //初始化函数 56 | -(BOOL) init:(NSString *)app_id mch_id:(NSString *)mch_id; 57 | -(NSString *) getDebugifo; 58 | -(long) getLasterrCode; 59 | //设置商户密钥 60 | -(void) setKey:(NSString *)key; 61 | //创建package签名 62 | -(NSString*) createMd5Sign:(NSMutableDictionary*)dict; 63 | //获取package带参数的签名包 64 | -(NSString *)genPackage:(NSMutableDictionary*)packageParams; 65 | //提交预支付 66 | -(NSString *)sendPrepay:(NSMutableDictionary *)prePayParams; 67 | //签名实例测试 68 | - ( NSMutableDictionary *)sendPay_demo:(NSString *)orderid title:(NSString *)ordertitle price:(NSString *)orderprice; 69 | @end -------------------------------------------------------------------------------- /微信支付/GBWXPay/WxPay/lib/payRequsestHandler.mm: -------------------------------------------------------------------------------- 1 | 2 | #import 3 | #import "payRequsestHandler.h" 4 | #import "GBWXPayManagerConfig.h" 5 | /* 6 | 服务器请求操作处理 7 | */ 8 | @implementation payRequsestHandler 9 | 10 | //初始化函数 11 | -(BOOL) init:(NSString *)app_id mch_id:(NSString *)mch_id; 12 | { 13 | //初始构造函数 14 | payUrl = @"https://api.mch.weixin.qq.com/pay/unifiedorder"; 15 | if (debugInfo == nil){ 16 | debugInfo = [NSMutableString string]; 17 | } 18 | [debugInfo setString:@""]; 19 | appid = app_id; 20 | mchid = mch_id; 21 | return YES; 22 | } 23 | //设置商户密钥 24 | -(void) setKey:(NSString *)key 25 | { 26 | spkey = [NSString stringWithString:key]; 27 | } 28 | //获取debug信息 29 | -(NSString*) getDebugifo 30 | { 31 | NSString *res = [NSString stringWithString:debugInfo]; 32 | [debugInfo setString:@""]; 33 | return res; 34 | } 35 | //获取最后服务返回错误代码 36 | -(long) getLasterrCode 37 | { 38 | return last_errcode; 39 | } 40 | //创建package签名 41 | -(NSString*) createMd5Sign:(NSMutableDictionary*)dict 42 | { 43 | NSMutableString *contentString =[NSMutableString string]; 44 | NSArray *keys = [dict allKeys]; 45 | //按字母顺序排序 46 | NSArray *sortedArray = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { 47 | return [obj1 compare:obj2 options:NSNumericSearch]; 48 | }]; 49 | //拼接字符串 50 | for (NSString *categoryId in sortedArray) { 51 | if ( ![[dict objectForKey:categoryId] isEqualToString:@""] 52 | && ![categoryId isEqualToString:@"sign"] 53 | && ![categoryId isEqualToString:@"key"] 54 | ) 55 | { 56 | [contentString appendFormat:@"%@=%@&", categoryId, [dict objectForKey:categoryId]]; 57 | } 58 | 59 | } 60 | //添加key字段 61 | [contentString appendFormat:@"key=%@", spkey]; 62 | //得到MD5 sign签名 63 | NSString *md5Sign =[WXUtil md5:contentString]; 64 | 65 | //输出Debug Info 66 | [debugInfo appendFormat:@"MD5签名字符串:\n%@\n\n",contentString]; 67 | 68 | return md5Sign; 69 | } 70 | 71 | //获取package带参数的签名包 72 | -(NSString *)genPackage:(NSMutableDictionary*)packageParams 73 | { 74 | NSString *sign; 75 | NSMutableString *reqPars=[NSMutableString string]; 76 | //生成签名 77 | sign = [self createMd5Sign:packageParams]; 78 | //生成xml的package 79 | NSArray *keys = [packageParams allKeys]; 80 | [reqPars appendString:@"\n"]; 81 | for (NSString *categoryId in keys) { 82 | [reqPars appendFormat:@"<%@>%@\n", categoryId, [packageParams objectForKey:categoryId],categoryId]; 83 | } 84 | [reqPars appendFormat:@"%@\n", sign]; 85 | 86 | return [NSString stringWithString:reqPars]; 87 | } 88 | //提交预支付 89 | -(NSString *)sendPrepay:(NSMutableDictionary *)prePayParams 90 | { 91 | NSString *prepayid = nil; 92 | 93 | //获取提交支付 94 | NSString *send = [self genPackage:prePayParams]; 95 | 96 | //输出Debug Info 97 | [debugInfo appendFormat:@"API链接:%@\n", payUrl]; 98 | [debugInfo appendFormat:@"发送的xml:%@\n", send]; 99 | 100 | //发送请求post xml数据 101 | NSData *res = [WXUtil httpSend:payUrl method:@"POST" data:send]; 102 | 103 | //输出Debug Info 104 | [debugInfo appendFormat:@"服务器返回:\n%@\n\n",[[NSString alloc] initWithData:res encoding:NSUTF8StringEncoding]]; 105 | 106 | XMLHelper *xml = [[XMLHelper alloc] init]; 107 | 108 | //开始解析 109 | [xml startParse:res]; 110 | 111 | NSMutableDictionary *resParams = [xml getDict]; 112 | 113 | //判断返回 114 | NSString *return_code = [resParams objectForKey:@"return_code"]; 115 | NSString *result_code = [resParams objectForKey:@"result_code"]; 116 | if ( [return_code isEqualToString:@"SUCCESS"] ) 117 | { 118 | //生成返回数据的签名 119 | NSString *sign = [self createMd5Sign:resParams ]; 120 | NSString *send_sign =[resParams objectForKey:@"sign"] ; 121 | 122 | //验证签名正确性 123 | if( [sign isEqualToString:send_sign]){ 124 | if( [result_code isEqualToString:@"SUCCESS"]) { 125 | //验证业务处理状态 126 | prepayid = [resParams objectForKey:@"prepay_id"]; 127 | return_code = 0; 128 | 129 | [debugInfo appendFormat:@"获取预支付交易标示成功!\n"]; 130 | } 131 | }else{ 132 | last_errcode = 1; 133 | [debugInfo appendFormat:@"gen_sign=%@\n _sign=%@\n",sign,send_sign]; 134 | [debugInfo appendFormat:@"服务器返回签名验证错误!!!\n"]; 135 | } 136 | }else{ 137 | last_errcode = 2; 138 | [debugInfo appendFormat:@"接口返回错误!!!\n"]; 139 | } 140 | 141 | return prepayid; 142 | } 143 | //============================================================ 144 | // V3V4支付流程模拟实现,只作帐号验证和演示 145 | // 注意:此demo只适合开发调试,参数配置和参数加密需要放到服务器端处理 146 | // 服务器端Demo请查看包的文件 147 | // 更新时间:2015年3月3日 148 | // 负责人:李启波(marcyli) 149 | //============================================================ 150 | - ( NSMutableDictionary *)sendPay_demo:(NSString *)orderid title:(NSString *)ordertitle price:(NSString *)orderprice 151 | { 152 | //订单标题,展示给用户 153 | NSString *order_name = ordertitle; 154 | //订单金额,单位(分) 155 | NSString *order_price = orderprice;//1分钱测试 156 | 157 | 158 | //================================ 159 | //预付单参数订单设置 160 | //================================ 161 | srand( (unsigned)time(0) ); 162 | NSString *noncestr = [NSString stringWithFormat:@"%d", rand()]; 163 | NSMutableDictionary *packageParams = [NSMutableDictionary dictionary]; 164 | 165 | [packageParams setObject: appid forKey:@"appid"]; //开放平台appid 166 | [packageParams setObject: mchid forKey:@"mch_id"]; //商户号 167 | [packageParams setObject: @"APP-001" forKey:@"device_info"]; //支付设备号或门店号 168 | [packageParams setObject: noncestr forKey:@"nonce_str"]; //随机串 169 | [packageParams setObject: @"APP" forKey:@"trade_type"]; //支付类型,固定为APP 170 | [packageParams setObject: order_name forKey:@"body"]; //订单描述,展示给用户 171 | [packageParams setObject: NOTIFY_URL forKey:@"notify_url"]; //支付结果异步通知 172 | [packageParams setObject: orderid forKey:@"out_trade_no"];//商户订单号 173 | [packageParams setObject: @"196.168.1.1" forKey:@"spbill_create_ip"];//发器支付的机器ip 174 | [packageParams setObject: order_price forKey:@"total_fee"]; //订单金额,单位为分 175 | 176 | //获取prepayId(预支付交易会话标识) 177 | NSString *prePayid; 178 | prePayid = [self sendPrepay:packageParams]; 179 | 180 | if ( prePayid != nil) { 181 | //获取到prepayid后进行第二次签名 182 | 183 | NSString *package, *time_stamp, *nonce_str; 184 | //设置支付参数 185 | time_t now; 186 | time(&now); 187 | time_stamp = [NSString stringWithFormat:@"%ld", now]; 188 | nonce_str = [WXUtil md5:time_stamp]; 189 | //重新按提交格式组包,微信客户端暂只支持package=Sign=WXPay格式,须考虑升级后支持携带package具体参数的情况 190 | //package = [NSString stringWithFormat:@"Sign=%@",package]; 191 | package = @"Sign=WXPay"; 192 | //第二次签名参数列表 193 | NSMutableDictionary *signParams = [NSMutableDictionary dictionary]; 194 | [signParams setObject: appid forKey:@"appid"]; 195 | [signParams setObject: nonce_str forKey:@"noncestr"]; 196 | [signParams setObject: package forKey:@"package"]; 197 | [signParams setObject: mchid forKey:@"partnerid"]; 198 | [signParams setObject: time_stamp forKey:@"timestamp"]; 199 | [signParams setObject: prePayid forKey:@"prepayid"]; 200 | //[signParams setObject: @"MD5" forKey:@"signType"]; 201 | //生成签名 202 | NSString *sign = [self createMd5Sign:signParams]; 203 | 204 | //添加签名 205 | [signParams setObject: sign forKey:@"sign"]; 206 | 207 | [debugInfo appendFormat:@"第二步签名成功,sign=%@\n",sign]; 208 | 209 | //返回参数列表 210 | return signParams; 211 | 212 | }else{ 213 | [debugInfo appendFormat:@"获取prepayid失败!\n"]; 214 | } 215 | return nil; 216 | } 217 | @end -------------------------------------------------------------------------------- /微信支付/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "29x29", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "29x29", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "40x40", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "40x40", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "60x60", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "60x60", 31 | "scale" : "3x" 32 | } 33 | ], 34 | "info" : { 35 | "version" : 1, 36 | "author" : "xcode" 37 | } 38 | } -------------------------------------------------------------------------------- /微信支付/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | LSApplicationQueriesSchemes 6 | 7 | weixin 8 | 9 | NSAppTransportSecurity 10 | 11 | NSAllowsArbitraryLoads 12 | 13 | 14 | CFBundleDevelopmentRegion 15 | en 16 | CFBundleExecutable 17 | $(EXECUTABLE_NAME) 18 | CFBundleIdentifier 19 | com.zhangguobing.$(PRODUCT_NAME:rfc1034identifier) 20 | CFBundleInfoDictionaryVersion 21 | 6.0 22 | CFBundleName 23 | $(PRODUCT_NAME) 24 | CFBundlePackageType 25 | APPL 26 | CFBundleShortVersionString 27 | 1.0 28 | CFBundleSignature 29 | ???? 30 | CFBundleURLTypes 31 | 32 | 33 | CFBundleTypeRole 34 | Editor 35 | CFBundleURLName 36 | WXPay 37 | CFBundleURLSchemes 38 | 39 | wx1adbcf4754b31ba7 40 | 41 | 42 | 43 | CFBundleVersion 44 | 1 45 | LSRequiresIPhoneOS 46 | 47 | UILaunchStoryboardName 48 | LaunchScreen 49 | UIMainStoryboardFile 50 | Main 51 | UIRequiredDeviceCapabilities 52 | 53 | armv7 54 | 55 | UISupportedInterfaceOrientations 56 | 57 | UIInterfaceOrientationPortrait 58 | UIInterfaceOrientationLandscapeLeft 59 | UIInterfaceOrientationLandscapeRight 60 | 61 | 62 | 63 | -------------------------------------------------------------------------------- /微信支付/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // 微信支付 4 | // 5 | // Created by 张国兵 on 15/7/24. 6 | // Copyright (c) 2015年 zhangguobing. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | 14 | @end 15 | 16 | -------------------------------------------------------------------------------- /微信支付/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // 微信支付 4 | // 5 | // Created by 张国兵 on 15/7/24. 6 | // Copyright (c) 2015年 zhangguobing. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "GBWXPayManager.h" 11 | 12 | @interface ViewController () 13 | 14 | @end 15 | 16 | @implementation ViewController 17 | -(void)dealloc{ 18 | //移除监听 19 | [[NSNotificationCenter defaultCenter ]removeObserver:self]; 20 | 21 | } 22 | - (void)viewDidLoad { 23 | [super viewDidLoad]; 24 | UIButton*pay=[UIButton buttonWithType:UIButtonTypeCustom]; 25 | pay.backgroundColor=[UIColor orangeColor]; 26 | pay.frame=CGRectMake(100, 100, 100, 40); 27 | [pay setTitleColor:[UIColor blackColor] forState:UIControlStateNormal]; 28 | [pay setTitle:@"微信支付" forState:UIControlStateNormal]; 29 | [pay addTarget:self action:@selector(weixinSendPay) forControlEvents:UIControlEventTouchUpInside]; 30 | 31 | [self.view addSubview:pay]; 32 | 33 | //注册监听-微信 34 | [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(dealWXpayResult:) name:@"WXpayresult" object:nil]; 35 | 36 | 37 | 38 | 39 | // Do any additional setup after loading the view, typically from a nib. 40 | } 41 | #pragma mark - 微信支付 42 | - (void)weixinSendPay 43 | { 44 | 45 | 46 | NSString *orderno = [NSString stringWithFormat:@"%ld",time(0)]; 47 | 48 | [GBWXPayManager wxpayWithOrderID:orderno orderTitle:@"测试" amount:@"0.01"]; 49 | 50 | 51 | 52 | } 53 | 54 | -(void)dealWXpayResult:(NSNotification*)notification{ 55 | NSString*result=notification.object; 56 | if([result isEqualToString:@"1"]){ 57 | 58 | //在这里写支付成功之后的回调操作 59 | NSLog(@"微信支付成功"); 60 | 61 | }else{ 62 | //在这里写支付失败之后的回调操作 63 | NSLog(@"微信支付失败"); 64 | } 65 | 66 | 67 | 68 | } 69 | //客户端提示信息 70 | - (void)alert:(NSString *)title msg:(NSString *)msg 71 | { 72 | UIAlertView *alter = [[UIAlertView alloc] initWithTitle:title message:msg delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil]; 73 | 74 | [alter show]; 75 | } 76 | 77 | - (void)didReceiveMemoryWarning { 78 | [super didReceiveMemoryWarning]; 79 | // Dispose of any resources that can be recreated. 80 | } 81 | 82 | @end 83 | -------------------------------------------------------------------------------- /微信支付/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // 微信支付 4 | // 5 | // Created by 张国兵 on 15/7/24. 6 | // Copyright (c) 2015年 zhangguobing. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "AppDelegate.h" 11 | 12 | int main(int argc, char * argv[]) { 13 | @autoreleasepool { 14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /微信支付Tests/Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | $(EXECUTABLE_NAME) 9 | CFBundleIdentifier 10 | com.zhangguobing.$(PRODUCT_NAME:rfc1034identifier) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundleName 14 | $(PRODUCT_NAME) 15 | CFBundlePackageType 16 | BNDL 17 | CFBundleShortVersionString 18 | 1.0 19 | CFBundleSignature 20 | ???? 21 | CFBundleVersion 22 | 1 23 | 24 | 25 | -------------------------------------------------------------------------------- /微信支付Tests/____Tests.m: -------------------------------------------------------------------------------- 1 | // 2 | // ____Tests.m 3 | // 微信支付Tests 4 | // 5 | // Created by 张国兵 on 15/7/24. 6 | // Copyright (c) 2015年 zhangguobing. All rights reserved. 7 | // 8 | 9 | #import 10 | #import 11 | 12 | @interface ____Tests : XCTestCase 13 | 14 | @end 15 | 16 | @implementation ____Tests 17 | 18 | - (void)setUp { 19 | [super setUp]; 20 | // Put setup code here. This method is called before the invocation of each test method in the class. 21 | } 22 | 23 | - (void)tearDown { 24 | // Put teardown code here. This method is called after the invocation of each test method in the class. 25 | [super tearDown]; 26 | } 27 | 28 | - (void)testExample { 29 | // This is an example of a functional test case. 30 | XCTAssert(YES, @"Pass"); 31 | } 32 | 33 | - (void)testPerformanceExample { 34 | // This is an example of a performance test case. 35 | [self measureBlock:^{ 36 | // Put the code you want to measure the time of here. 37 | }]; 38 | } 39 | 40 | @end 41 | --------------------------------------------------------------------------------