├── .gitignore ├── Podfile ├── Podfile.lock ├── README.md ├── WechatPayDemo.xcodeproj ├── project.pbxproj ├── project.xcworkspace │ └── contents.xcworkspacedata └── xcuserdata │ └── alvin.xcuserdatad │ └── xcschemes │ ├── WechatPayDemo.xcscheme │ └── xcschememanagement.plist ├── WechatPayDemo.xcworkspace └── contents.xcworkspacedata ├── WechatPayDemo ├── AppDelegate.h ├── AppDelegate.m ├── Base.lproj │ └── Main.storyboard ├── CommonUtil.h ├── CommonUtil.m ├── Constant.h ├── Images.xcassets │ ├── AppIcon.appiconset │ │ └── Contents.json │ └── LaunchImage.launchimage │ │ └── Contents.json ├── ViewController.h ├── ViewController.m ├── WXPayClient.h ├── WXPayClient.m ├── WeChatSDK_64 │ ├── WXApi.h │ ├── WXApiObject.h │ └── libWeChatSDK.a ├── WechatPayDemo-Info.plist ├── WechatPayDemo-Prefix.pch ├── en.lproj │ └── InfoPlist.strings └── main.m └── WechatPayDemoTests ├── WechatPayDemoTests-Info.plist ├── WechatPayDemoTests.m └── en.lproj └── InfoPlist.strings /.gitignore: -------------------------------------------------------------------------------- 1 | # Created by https://www.gitignore.io 2 | 3 | ### Objective-C ### 4 | # Xcode 5 | # 6 | build/ 7 | *.pbxuser 8 | !default.pbxuser 9 | *.mode1v3 10 | !default.mode1v3 11 | *.mode2v3 12 | !default.mode2v3 13 | *.perspectivev3 14 | !default.perspectivev3 15 | xcuserdata 16 | *.xccheckout 17 | *.moved-aside 18 | DerivedData 19 | *.hmap 20 | *.ipa 21 | *.xcuserstate 22 | 23 | # CocoaPods 24 | # 25 | # We recommend against adding the Pods directory to your .gitignore. However 26 | # you should judge for yourself, the pros and cons are mentioned at: 27 | # http://guides.cocoapods.org/using/using-cocoapods.html#should-i-ignore-the-pods-directory-in-source-control 28 | # 29 | Pods/ 30 | 31 | -------------------------------------------------------------------------------- /Podfile: -------------------------------------------------------------------------------- 1 | platform :ios 2 | 3 | target 'WechatPayDemo' do 4 | pod 'ASIHTTPRequest', '~> 1.8.2' 5 | pod 'MBProgressHUD', '~> 0.8' 6 | end -------------------------------------------------------------------------------- /Podfile.lock: -------------------------------------------------------------------------------- 1 | PODS: 2 | - ASIHTTPRequest (1.8.2): 3 | - ASIHTTPRequest/ASIWebPageRequest (= 1.8.2) 4 | - ASIHTTPRequest/CloudFiles (= 1.8.2) 5 | - ASIHTTPRequest/Core (= 1.8.2) 6 | - ASIHTTPRequest/S3 (= 1.8.2) 7 | - ASIHTTPRequest/ASIWebPageRequest (1.8.2): 8 | - ASIHTTPRequest/Core 9 | - ASIHTTPRequest/CloudFiles (1.8.2): 10 | - ASIHTTPRequest/Core 11 | - ASIHTTPRequest/Core (1.8.2): 12 | - Reachability 13 | - ASIHTTPRequest/S3 (1.8.2): 14 | - ASIHTTPRequest/Core 15 | - MBProgressHUD (0.9.2) 16 | - Reachability (3.1.1) 17 | 18 | DEPENDENCIES: 19 | - ASIHTTPRequest (~> 1.8.2) 20 | - MBProgressHUD (~> 0.8) 21 | 22 | SPEC CHECKSUMS: 23 | ASIHTTPRequest: ec013992946676b7978dcbde6396d57312d21db4 24 | MBProgressHUD: 1569cf7ace17a8bac47aabfbb8580a49690386d1 25 | Reachability: dd9aa4fb6667b9f787690a74f53cb7634ce99893 26 | 27 | PODFILE CHECKSUM: 9a3b157baf04e1588d74b78102f3237a23d8aaa5 28 | 29 | COCOAPODS: 1.0.1 30 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # WechatPayDemo 2 | 3 | --- 4 | 5 | 这是非官方的微信支付 Demo,基于微信 SDK v2.0.2_V3 构建,可以从[这里](https://open.weixin.qq.com/cgi-bin/frame?t=resource/res_main_tmpl&lang=zh_CN)下载到最新的官方 iOS 开发资料。(里面的参数都是从 Android 版 Demo 中提取) 6 | 7 | ## Usage 8 | 9 | 这个项目依赖 [CocoaPods](http://cocoapods.org) 使用前请先在工程目录下执行: 10 | 11 | ``` 12 | pod install 13 | ``` 14 | 15 | 另外,可以在 ```AppDelegate.m``` 中替换已有的请求参数用于个人项目的测试。 16 | 17 | 而 ```package``` 里参数的含义可以参考[这里](https://github.com/gbammc/WechatPayDemo/issues/2)。:] 18 | 19 | ## 说明 20 | 21 | 创建这个 Repo 的原因是,微信官方并没有提供支付功能的 iOS Demo(只有 Android 版...),而且个人认为官方提供的文档也相当不靠谱,例如: 22 | 23 | 1.文档里代码示例出现基本错误 24 | 25 | ``` 26 | // 构造参数列表 27 | NSMutableDictionary params = [NSMutableDictionary dictionary]; [params setObject:@"WX" forKey:@"bank_type"]; 28 | [params setObject:@"千足金箍棒" forKey:@"body"]; 29 | 30 | ... 31 | 32 | // 进行md5摘要前,params内容为原始内容,未经过url encode处理 33 | String packageSign = package.md5.uppercaseString; 34 | return [NSString stringWithFormat:@"%@&sign=%@",paragramString,packageSign]; 35 | ``` 36 | 37 | 2.文档指示不清 38 | 39 | ``` 40 | package 生成方法: 41 | A)对所有传入参数按照字段名的 ASCII 码从小到大排序(字典序)后,使用 URL 键值对的格 式(即 key1=value1&key2=value2...)拼接成字符串 string1; 42 | B) 在 string1 最后拼接上 key=partnerKey 得到 stringSignTemp 字符串, 并对 stringSignTemp 进行 md5 运算,再将得到的字符串所有字符转换为大写,得到 sign 值 signValue。 43 | C)对 string1 中的所有键值对中的 value 进行 urlencode 转码,按照 a 步骤重新拼接成字符 串,得到 string2。对于 js 前端程序,一定要使用函数 encodeURIComponent 进行 urlencode 编码(注意!进行 urlencode 时要将空格转化为%20 而不是+)。 44 | D)将 sign=signValue 拼接到 string1 后面得到最终的 package 字符串。 45 | ``` 46 | 47 | C) 中出现的 string2 在后面再也没提到了,但其实就是```return [NSString stringWithFormat:@"%@&sign=%@",paragramString,packageSign];```里的```paragramString``` 48 | 49 | ``` 50 | 三、调起微信支付 51 | 将第二步生成的 prepayId 作为参数,调用微信 sdk 发送支付请求到微信。 52 | 代码示例如下: 53 | PayReq *request = [[[PayReq alloc] init] autorelease]; 54 | request.partnerId = _pactnerid; 55 | request.prepayId= _prapayid; 56 | Request.package = _package; 57 | request.nonceStr= _noncestr; 58 | request.timeStamp= _timestamp; 59 | request.sign= _sign; 60 | [WXApi safeSendReq:request]; 61 | 注意事项: 62 | 1.调起微信支付 SDK 时,请求参数中 package 需填写为:Sign=WXPay。 签名生成示例如下: 63 | // 构造参数列表 64 | NSMutableDictionary params = [NSMutableDictionary dictionary]; [params setObject:@"1234567" forKey:@"appid"]; 65 | [params setObject:@"111111" forKey:@"appkey"]; 66 | [params setObject:@"daadssas" forKey:@"noncestr"]; 67 | [params setObject:@"Sign=WXPay" forKey:@"package"]; 68 | [params setObject:@"123456" forKey:@"partnerid"]; 69 | [params setObject:@"123456" forKey:@"prepayid"]; 70 | [params setObject:@"12345" forKey:@"timestamp"]; 71 | ``` 72 | 73 | 文档中特地用红色标明了这句```[params setObject:@"Sign=WXPay" forKey:@"package"];```,而上面 request 中的 package 却是```Request.package = _package;```,可是经实验,request 的 package 也应该同样是```@"Sign=WXPay"```才能发起支付成功。 74 | 75 | 76 | -------------------------------------------------------------------------------- /WechatPayDemo.xcodeproj/project.pbxproj: -------------------------------------------------------------------------------- 1 | // !$*UTF8*$! 2 | { 3 | archiveVersion = 1; 4 | classes = { 5 | }; 6 | objectVersion = 46; 7 | objects = { 8 | 9 | /* Begin PBXBuildFile section */ 10 | 05DB2B0B49BA8E10F0210498 /* libPods-WechatPayDemo.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 33432559FF8C384CE380AFF3 /* libPods-WechatPayDemo.a */; }; 11 | E13067C31DAA16A70006D6DF /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = E13067C21DAA16A70006D6DF /* libz.tbd */; }; 12 | E13067C51DAA16AF0006D6DF /* libsqlite3.0.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = E13067C41DAA16AF0006D6DF /* libsqlite3.0.tbd */; }; 13 | E13067C71DAA16B40006D6DF /* Security.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E13067C61DAA16B40006D6DF /* Security.framework */; }; 14 | E13067C91DAA16C10006D6DF /* CoreTelephony.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E13067C81DAA16C10006D6DF /* CoreTelephony.framework */; }; 15 | E13067CB1DAA16CB0006D6DF /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E13067CA1DAA16CB0006D6DF /* SystemConfiguration.framework */; }; 16 | E13067CD1DAA1B2A0006D6DF /* libc++.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = E13067CC1DAA1B2A0006D6DF /* libc++.tbd */; }; 17 | E148FDC118DCB27A0021747E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E148FDC018DCB27A0021747E /* Foundation.framework */; }; 18 | E148FDC318DCB27A0021747E /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E148FDC218DCB27A0021747E /* CoreGraphics.framework */; }; 19 | E148FDC518DCB27A0021747E /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E148FDC418DCB27A0021747E /* UIKit.framework */; }; 20 | E148FDCB18DCB27A0021747E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = E148FDC918DCB27A0021747E /* InfoPlist.strings */; }; 21 | E148FDCD18DCB27A0021747E /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = E148FDCC18DCB27A0021747E /* main.m */; }; 22 | E148FDD118DCB27A0021747E /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E148FDD018DCB27A0021747E /* AppDelegate.m */; }; 23 | E148FDD418DCB27A0021747E /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = E148FDD218DCB27A0021747E /* Main.storyboard */; }; 24 | E148FDD718DCB27A0021747E /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E148FDD618DCB27A0021747E /* ViewController.m */; }; 25 | E148FDD918DCB27A0021747E /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E148FDD818DCB27A0021747E /* Images.xcassets */; }; 26 | E148FDE018DCB27B0021747E /* XCTest.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E148FDDF18DCB27B0021747E /* XCTest.framework */; }; 27 | E148FDE118DCB27B0021747E /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E148FDC018DCB27A0021747E /* Foundation.framework */; }; 28 | E148FDE218DCB27B0021747E /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E148FDC418DCB27A0021747E /* UIKit.framework */; }; 29 | E148FDEA18DCB27B0021747E /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = E148FDE818DCB27B0021747E /* InfoPlist.strings */; }; 30 | E148FDEC18DCB27B0021747E /* WechatPayDemoTests.m in Sources */ = {isa = PBXBuildFile; fileRef = E148FDEB18DCB27B0021747E /* WechatPayDemoTests.m */; }; 31 | E148FDFE18DCBB1E0021747E /* WXPayClient.m in Sources */ = {isa = PBXBuildFile; fileRef = E148FDFD18DCBB1E0021747E /* WXPayClient.m */; }; 32 | E148FE0218DCBE400021747E /* CommonUtil.m in Sources */ = {isa = PBXBuildFile; fileRef = E148FE0118DCBE400021747E /* CommonUtil.m */; }; 33 | E1BAF84819C5483F0095D079 /* libWeChatSDK.a in Frameworks */ = {isa = PBXBuildFile; fileRef = E1BAF84519C5483F0095D079 /* libWeChatSDK.a */; }; 34 | /* End PBXBuildFile section */ 35 | 36 | /* Begin PBXContainerItemProxy section */ 37 | E148FDE318DCB27B0021747E /* PBXContainerItemProxy */ = { 38 | isa = PBXContainerItemProxy; 39 | containerPortal = E148FDB518DCB27A0021747E /* Project object */; 40 | proxyType = 1; 41 | remoteGlobalIDString = E148FDBC18DCB27A0021747E; 42 | remoteInfo = WechatPayDemo; 43 | }; 44 | /* End PBXContainerItemProxy section */ 45 | 46 | /* Begin PBXFileReference section */ 47 | 076A105D5C4695800F4BD61D /* Pods-WechatPayDemo.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WechatPayDemo.release.xcconfig"; path = "Pods/Target Support Files/Pods-WechatPayDemo/Pods-WechatPayDemo.release.xcconfig"; sourceTree = ""; }; 48 | 33432559FF8C384CE380AFF3 /* libPods-WechatPayDemo.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-WechatPayDemo.a"; sourceTree = BUILT_PRODUCTS_DIR; }; 49 | 96108743CC9E003B49F757A9 /* Pods-WechatPayDemo.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-WechatPayDemo.debug.xcconfig"; path = "Pods/Target Support Files/Pods-WechatPayDemo/Pods-WechatPayDemo.debug.xcconfig"; sourceTree = ""; }; 50 | E13067C21DAA16A70006D6DF /* libz.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libz.tbd; path = usr/lib/libz.tbd; sourceTree = SDKROOT; }; 51 | E13067C41DAA16AF0006D6DF /* libsqlite3.0.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = libsqlite3.0.tbd; path = usr/lib/libsqlite3.0.tbd; sourceTree = SDKROOT; }; 52 | E13067C61DAA16B40006D6DF /* Security.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Security.framework; path = System/Library/Frameworks/Security.framework; sourceTree = SDKROOT; }; 53 | E13067C81DAA16C10006D6DF /* CoreTelephony.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreTelephony.framework; path = System/Library/Frameworks/CoreTelephony.framework; sourceTree = SDKROOT; }; 54 | E13067CA1DAA16CB0006D6DF /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = System/Library/Frameworks/SystemConfiguration.framework; sourceTree = SDKROOT; }; 55 | E13067CC1DAA1B2A0006D6DF /* libc++.tbd */ = {isa = PBXFileReference; lastKnownFileType = "sourcecode.text-based-dylib-definition"; name = "libc++.tbd"; path = "usr/lib/libc++.tbd"; sourceTree = SDKROOT; }; 56 | E148FDBD18DCB27A0021747E /* WechatPayDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = WechatPayDemo.app; sourceTree = BUILT_PRODUCTS_DIR; }; 57 | E148FDC018DCB27A0021747E /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; }; 58 | E148FDC218DCB27A0021747E /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; }; 59 | E148FDC418DCB27A0021747E /* UIKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = UIKit.framework; path = System/Library/Frameworks/UIKit.framework; sourceTree = SDKROOT; }; 60 | E148FDC818DCB27A0021747E /* WechatPayDemo-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "WechatPayDemo-Info.plist"; sourceTree = ""; }; 61 | E148FDCA18DCB27A0021747E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 62 | E148FDCC18DCB27A0021747E /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = ""; }; 63 | E148FDCE18DCB27A0021747E /* WechatPayDemo-Prefix.pch */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "WechatPayDemo-Prefix.pch"; sourceTree = ""; }; 64 | E148FDCF18DCB27A0021747E /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = ""; }; 65 | E148FDD018DCB27A0021747E /* AppDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = AppDelegate.m; sourceTree = ""; }; 66 | E148FDD318DCB27A0021747E /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/Main.storyboard; sourceTree = ""; }; 67 | E148FDD518DCB27A0021747E /* ViewController.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = ViewController.h; sourceTree = ""; }; 68 | E148FDD618DCB27A0021747E /* ViewController.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = ViewController.m; sourceTree = ""; }; 69 | E148FDD818DCB27A0021747E /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; 70 | E148FDDE18DCB27B0021747E /* WechatPayDemoTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = WechatPayDemoTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; 71 | E148FDDF18DCB27B0021747E /* XCTest.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = XCTest.framework; path = Library/Frameworks/XCTest.framework; sourceTree = DEVELOPER_DIR; }; 72 | E148FDE718DCB27B0021747E /* WechatPayDemoTests-Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = "WechatPayDemoTests-Info.plist"; sourceTree = ""; }; 73 | E148FDE918DCB27B0021747E /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = en.lproj/InfoPlist.strings; sourceTree = ""; }; 74 | E148FDEB18DCB27B0021747E /* WechatPayDemoTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = WechatPayDemoTests.m; sourceTree = ""; }; 75 | E148FDFC18DCBB1E0021747E /* WXPayClient.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXPayClient.h; sourceTree = ""; }; 76 | E148FDFD18DCBB1E0021747E /* WXPayClient.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = WXPayClient.m; sourceTree = ""; }; 77 | E148FDFF18DCBB3C0021747E /* Constant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = Constant.h; sourceTree = ""; }; 78 | E148FE0018DCBE400021747E /* CommonUtil.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = CommonUtil.h; sourceTree = ""; }; 79 | E148FE0118DCBE400021747E /* CommonUtil.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = CommonUtil.m; sourceTree = ""; }; 80 | E1BAF84519C5483F0095D079 /* libWeChatSDK.a */ = {isa = PBXFileReference; lastKnownFileType = archive.ar; path = libWeChatSDK.a; sourceTree = ""; }; 81 | E1BAF84619C5483F0095D079 /* WXApi.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXApi.h; sourceTree = ""; }; 82 | E1BAF84719C5483F0095D079 /* WXApiObject.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = WXApiObject.h; sourceTree = ""; }; 83 | /* End PBXFileReference section */ 84 | 85 | /* Begin PBXFrameworksBuildPhase section */ 86 | E148FDBA18DCB27A0021747E /* Frameworks */ = { 87 | isa = PBXFrameworksBuildPhase; 88 | buildActionMask = 2147483647; 89 | files = ( 90 | E13067CD1DAA1B2A0006D6DF /* libc++.tbd in Frameworks */, 91 | E13067CB1DAA16CB0006D6DF /* SystemConfiguration.framework in Frameworks */, 92 | E13067C91DAA16C10006D6DF /* CoreTelephony.framework in Frameworks */, 93 | E13067C71DAA16B40006D6DF /* Security.framework in Frameworks */, 94 | E13067C51DAA16AF0006D6DF /* libsqlite3.0.tbd in Frameworks */, 95 | E13067C31DAA16A70006D6DF /* libz.tbd in Frameworks */, 96 | E148FDC318DCB27A0021747E /* CoreGraphics.framework in Frameworks */, 97 | E148FDC518DCB27A0021747E /* UIKit.framework in Frameworks */, 98 | E148FDC118DCB27A0021747E /* Foundation.framework in Frameworks */, 99 | E1BAF84819C5483F0095D079 /* libWeChatSDK.a in Frameworks */, 100 | 05DB2B0B49BA8E10F0210498 /* libPods-WechatPayDemo.a in Frameworks */, 101 | ); 102 | runOnlyForDeploymentPostprocessing = 0; 103 | }; 104 | E148FDDB18DCB27B0021747E /* Frameworks */ = { 105 | isa = PBXFrameworksBuildPhase; 106 | buildActionMask = 2147483647; 107 | files = ( 108 | E148FDE018DCB27B0021747E /* XCTest.framework in Frameworks */, 109 | E148FDE218DCB27B0021747E /* UIKit.framework in Frameworks */, 110 | E148FDE118DCB27B0021747E /* Foundation.framework in Frameworks */, 111 | ); 112 | runOnlyForDeploymentPostprocessing = 0; 113 | }; 114 | /* End PBXFrameworksBuildPhase section */ 115 | 116 | /* Begin PBXGroup section */ 117 | 21767182DDE689413A54BDA8 /* Pods */ = { 118 | isa = PBXGroup; 119 | children = ( 120 | 96108743CC9E003B49F757A9 /* Pods-WechatPayDemo.debug.xcconfig */, 121 | 076A105D5C4695800F4BD61D /* Pods-WechatPayDemo.release.xcconfig */, 122 | ); 123 | name = Pods; 124 | sourceTree = ""; 125 | }; 126 | E148FDB418DCB27A0021747E = { 127 | isa = PBXGroup; 128 | children = ( 129 | E148FDC618DCB27A0021747E /* WechatPayDemo */, 130 | E148FDE518DCB27B0021747E /* WechatPayDemoTests */, 131 | E148FDBF18DCB27A0021747E /* Frameworks */, 132 | E148FDBE18DCB27A0021747E /* Products */, 133 | 21767182DDE689413A54BDA8 /* Pods */, 134 | ); 135 | sourceTree = ""; 136 | }; 137 | E148FDBE18DCB27A0021747E /* Products */ = { 138 | isa = PBXGroup; 139 | children = ( 140 | E148FDBD18DCB27A0021747E /* WechatPayDemo.app */, 141 | E148FDDE18DCB27B0021747E /* WechatPayDemoTests.xctest */, 142 | ); 143 | name = Products; 144 | sourceTree = ""; 145 | }; 146 | E148FDBF18DCB27A0021747E /* Frameworks */ = { 147 | isa = PBXGroup; 148 | children = ( 149 | E13067CC1DAA1B2A0006D6DF /* libc++.tbd */, 150 | E13067CA1DAA16CB0006D6DF /* SystemConfiguration.framework */, 151 | E13067C81DAA16C10006D6DF /* CoreTelephony.framework */, 152 | E13067C61DAA16B40006D6DF /* Security.framework */, 153 | E13067C41DAA16AF0006D6DF /* libsqlite3.0.tbd */, 154 | E13067C21DAA16A70006D6DF /* libz.tbd */, 155 | E148FDC018DCB27A0021747E /* Foundation.framework */, 156 | E148FDC218DCB27A0021747E /* CoreGraphics.framework */, 157 | E148FDC418DCB27A0021747E /* UIKit.framework */, 158 | E148FDDF18DCB27B0021747E /* XCTest.framework */, 159 | 33432559FF8C384CE380AFF3 /* libPods-WechatPayDemo.a */, 160 | ); 161 | name = Frameworks; 162 | sourceTree = ""; 163 | }; 164 | E148FDC618DCB27A0021747E /* WechatPayDemo */ = { 165 | isa = PBXGroup; 166 | children = ( 167 | E148FDCF18DCB27A0021747E /* AppDelegate.h */, 168 | E148FDD018DCB27A0021747E /* AppDelegate.m */, 169 | E148FDFF18DCBB3C0021747E /* Constant.h */, 170 | E148FDD218DCB27A0021747E /* Main.storyboard */, 171 | E148FDD518DCB27A0021747E /* ViewController.h */, 172 | E148FDD618DCB27A0021747E /* ViewController.m */, 173 | E148FE0018DCBE400021747E /* CommonUtil.h */, 174 | E148FE0118DCBE400021747E /* CommonUtil.m */, 175 | E148FDFC18DCBB1E0021747E /* WXPayClient.h */, 176 | E148FDFD18DCBB1E0021747E /* WXPayClient.m */, 177 | E1BAF84419C5483F0095D079 /* WeChatSDK_64 */, 178 | E148FDD818DCB27A0021747E /* Images.xcassets */, 179 | E148FDC718DCB27A0021747E /* Supporting Files */, 180 | ); 181 | path = WechatPayDemo; 182 | sourceTree = ""; 183 | }; 184 | E148FDC718DCB27A0021747E /* Supporting Files */ = { 185 | isa = PBXGroup; 186 | children = ( 187 | E148FDC818DCB27A0021747E /* WechatPayDemo-Info.plist */, 188 | E148FDC918DCB27A0021747E /* InfoPlist.strings */, 189 | E148FDCC18DCB27A0021747E /* main.m */, 190 | E148FDCE18DCB27A0021747E /* WechatPayDemo-Prefix.pch */, 191 | ); 192 | name = "Supporting Files"; 193 | sourceTree = ""; 194 | }; 195 | E148FDE518DCB27B0021747E /* WechatPayDemoTests */ = { 196 | isa = PBXGroup; 197 | children = ( 198 | E148FDEB18DCB27B0021747E /* WechatPayDemoTests.m */, 199 | E148FDE618DCB27B0021747E /* Supporting Files */, 200 | ); 201 | path = WechatPayDemoTests; 202 | sourceTree = ""; 203 | }; 204 | E148FDE618DCB27B0021747E /* Supporting Files */ = { 205 | isa = PBXGroup; 206 | children = ( 207 | E148FDE718DCB27B0021747E /* WechatPayDemoTests-Info.plist */, 208 | E148FDE818DCB27B0021747E /* InfoPlist.strings */, 209 | ); 210 | name = "Supporting Files"; 211 | sourceTree = ""; 212 | }; 213 | E1BAF84419C5483F0095D079 /* WeChatSDK_64 */ = { 214 | isa = PBXGroup; 215 | children = ( 216 | E1BAF84519C5483F0095D079 /* libWeChatSDK.a */, 217 | E1BAF84619C5483F0095D079 /* WXApi.h */, 218 | E1BAF84719C5483F0095D079 /* WXApiObject.h */, 219 | ); 220 | path = WeChatSDK_64; 221 | sourceTree = ""; 222 | }; 223 | /* End PBXGroup section */ 224 | 225 | /* Begin PBXNativeTarget section */ 226 | E148FDBC18DCB27A0021747E /* WechatPayDemo */ = { 227 | isa = PBXNativeTarget; 228 | buildConfigurationList = E148FDEF18DCB27B0021747E /* Build configuration list for PBXNativeTarget "WechatPayDemo" */; 229 | buildPhases = ( 230 | 50ADF8AEB8BD01FEB348220D /* [CP] Check Pods Manifest.lock */, 231 | E148FDB918DCB27A0021747E /* Sources */, 232 | E148FDBA18DCB27A0021747E /* Frameworks */, 233 | E148FDBB18DCB27A0021747E /* Resources */, 234 | 49DEC45F59A24BACA5E4EF3E /* [CP] Embed Pods Frameworks */, 235 | FAC471BF3EB9BF8BA8213839 /* [CP] Copy Pods Resources */, 236 | ); 237 | buildRules = ( 238 | ); 239 | dependencies = ( 240 | ); 241 | name = WechatPayDemo; 242 | productName = WechatPayDemo; 243 | productReference = E148FDBD18DCB27A0021747E /* WechatPayDemo.app */; 244 | productType = "com.apple.product-type.application"; 245 | }; 246 | E148FDDD18DCB27B0021747E /* WechatPayDemoTests */ = { 247 | isa = PBXNativeTarget; 248 | buildConfigurationList = E148FDF218DCB27B0021747E /* Build configuration list for PBXNativeTarget "WechatPayDemoTests" */; 249 | buildPhases = ( 250 | E148FDDA18DCB27B0021747E /* Sources */, 251 | E148FDDB18DCB27B0021747E /* Frameworks */, 252 | E148FDDC18DCB27B0021747E /* Resources */, 253 | ); 254 | buildRules = ( 255 | ); 256 | dependencies = ( 257 | E148FDE418DCB27B0021747E /* PBXTargetDependency */, 258 | ); 259 | name = WechatPayDemoTests; 260 | productName = WechatPayDemoTests; 261 | productReference = E148FDDE18DCB27B0021747E /* WechatPayDemoTests.xctest */; 262 | productType = "com.apple.product-type.bundle.unit-test"; 263 | }; 264 | /* End PBXNativeTarget section */ 265 | 266 | /* Begin PBXProject section */ 267 | E148FDB518DCB27A0021747E /* Project object */ = { 268 | isa = PBXProject; 269 | attributes = { 270 | LastUpgradeCheck = 0800; 271 | ORGANIZATIONNAME = Alvin; 272 | TargetAttributes = { 273 | E148FDBC18DCB27A0021747E = { 274 | DevelopmentTeam = 4Y65NZLKET; 275 | }; 276 | E148FDDD18DCB27B0021747E = { 277 | TestTargetID = E148FDBC18DCB27A0021747E; 278 | }; 279 | }; 280 | }; 281 | buildConfigurationList = E148FDB818DCB27A0021747E /* Build configuration list for PBXProject "WechatPayDemo" */; 282 | compatibilityVersion = "Xcode 3.2"; 283 | developmentRegion = English; 284 | hasScannedForEncodings = 0; 285 | knownRegions = ( 286 | en, 287 | Base, 288 | ); 289 | mainGroup = E148FDB418DCB27A0021747E; 290 | productRefGroup = E148FDBE18DCB27A0021747E /* Products */; 291 | projectDirPath = ""; 292 | projectRoot = ""; 293 | targets = ( 294 | E148FDBC18DCB27A0021747E /* WechatPayDemo */, 295 | E148FDDD18DCB27B0021747E /* WechatPayDemoTests */, 296 | ); 297 | }; 298 | /* End PBXProject section */ 299 | 300 | /* Begin PBXResourcesBuildPhase section */ 301 | E148FDBB18DCB27A0021747E /* Resources */ = { 302 | isa = PBXResourcesBuildPhase; 303 | buildActionMask = 2147483647; 304 | files = ( 305 | E148FDD918DCB27A0021747E /* Images.xcassets in Resources */, 306 | E148FDCB18DCB27A0021747E /* InfoPlist.strings in Resources */, 307 | E148FDD418DCB27A0021747E /* Main.storyboard in Resources */, 308 | ); 309 | runOnlyForDeploymentPostprocessing = 0; 310 | }; 311 | E148FDDC18DCB27B0021747E /* Resources */ = { 312 | isa = PBXResourcesBuildPhase; 313 | buildActionMask = 2147483647; 314 | files = ( 315 | E148FDEA18DCB27B0021747E /* InfoPlist.strings in Resources */, 316 | ); 317 | runOnlyForDeploymentPostprocessing = 0; 318 | }; 319 | /* End PBXResourcesBuildPhase section */ 320 | 321 | /* Begin PBXShellScriptBuildPhase section */ 322 | 49DEC45F59A24BACA5E4EF3E /* [CP] Embed Pods Frameworks */ = { 323 | isa = PBXShellScriptBuildPhase; 324 | buildActionMask = 2147483647; 325 | files = ( 326 | ); 327 | inputPaths = ( 328 | ); 329 | name = "[CP] Embed Pods Frameworks"; 330 | outputPaths = ( 331 | ); 332 | runOnlyForDeploymentPostprocessing = 0; 333 | shellPath = /bin/sh; 334 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-WechatPayDemo/Pods-WechatPayDemo-frameworks.sh\"\n"; 335 | showEnvVarsInLog = 0; 336 | }; 337 | 50ADF8AEB8BD01FEB348220D /* [CP] Check Pods Manifest.lock */ = { 338 | isa = PBXShellScriptBuildPhase; 339 | buildActionMask = 2147483647; 340 | files = ( 341 | ); 342 | inputPaths = ( 343 | ); 344 | name = "[CP] Check Pods Manifest.lock"; 345 | outputPaths = ( 346 | ); 347 | runOnlyForDeploymentPostprocessing = 0; 348 | shellPath = /bin/sh; 349 | shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n"; 350 | showEnvVarsInLog = 0; 351 | }; 352 | FAC471BF3EB9BF8BA8213839 /* [CP] Copy Pods Resources */ = { 353 | isa = PBXShellScriptBuildPhase; 354 | buildActionMask = 2147483647; 355 | files = ( 356 | ); 357 | inputPaths = ( 358 | ); 359 | name = "[CP] Copy Pods Resources"; 360 | outputPaths = ( 361 | ); 362 | runOnlyForDeploymentPostprocessing = 0; 363 | shellPath = /bin/sh; 364 | shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-WechatPayDemo/Pods-WechatPayDemo-resources.sh\"\n"; 365 | showEnvVarsInLog = 0; 366 | }; 367 | /* End PBXShellScriptBuildPhase section */ 368 | 369 | /* Begin PBXSourcesBuildPhase section */ 370 | E148FDB918DCB27A0021747E /* Sources */ = { 371 | isa = PBXSourcesBuildPhase; 372 | buildActionMask = 2147483647; 373 | files = ( 374 | E148FE0218DCBE400021747E /* CommonUtil.m in Sources */, 375 | E148FDFE18DCBB1E0021747E /* WXPayClient.m in Sources */, 376 | E148FDD718DCB27A0021747E /* ViewController.m in Sources */, 377 | E148FDD118DCB27A0021747E /* AppDelegate.m in Sources */, 378 | E148FDCD18DCB27A0021747E /* main.m in Sources */, 379 | ); 380 | runOnlyForDeploymentPostprocessing = 0; 381 | }; 382 | E148FDDA18DCB27B0021747E /* Sources */ = { 383 | isa = PBXSourcesBuildPhase; 384 | buildActionMask = 2147483647; 385 | files = ( 386 | E148FDEC18DCB27B0021747E /* WechatPayDemoTests.m in Sources */, 387 | ); 388 | runOnlyForDeploymentPostprocessing = 0; 389 | }; 390 | /* End PBXSourcesBuildPhase section */ 391 | 392 | /* Begin PBXTargetDependency section */ 393 | E148FDE418DCB27B0021747E /* PBXTargetDependency */ = { 394 | isa = PBXTargetDependency; 395 | target = E148FDBC18DCB27A0021747E /* WechatPayDemo */; 396 | targetProxy = E148FDE318DCB27B0021747E /* PBXContainerItemProxy */; 397 | }; 398 | /* End PBXTargetDependency section */ 399 | 400 | /* Begin PBXVariantGroup section */ 401 | E148FDC918DCB27A0021747E /* InfoPlist.strings */ = { 402 | isa = PBXVariantGroup; 403 | children = ( 404 | E148FDCA18DCB27A0021747E /* en */, 405 | ); 406 | name = InfoPlist.strings; 407 | sourceTree = ""; 408 | }; 409 | E148FDD218DCB27A0021747E /* Main.storyboard */ = { 410 | isa = PBXVariantGroup; 411 | children = ( 412 | E148FDD318DCB27A0021747E /* Base */, 413 | ); 414 | name = Main.storyboard; 415 | sourceTree = ""; 416 | }; 417 | E148FDE818DCB27B0021747E /* InfoPlist.strings */ = { 418 | isa = PBXVariantGroup; 419 | children = ( 420 | E148FDE918DCB27B0021747E /* en */, 421 | ); 422 | name = InfoPlist.strings; 423 | sourceTree = ""; 424 | }; 425 | /* End PBXVariantGroup section */ 426 | 427 | /* Begin XCBuildConfiguration section */ 428 | E148FDED18DCB27B0021747E /* Debug */ = { 429 | isa = XCBuildConfiguration; 430 | buildSettings = { 431 | ALWAYS_SEARCH_USER_PATHS = NO; 432 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 433 | CLANG_CXX_LIBRARY = "libc++"; 434 | CLANG_ENABLE_MODULES = YES; 435 | CLANG_ENABLE_OBJC_ARC = YES; 436 | CLANG_WARN_BOOL_CONVERSION = YES; 437 | CLANG_WARN_CONSTANT_CONVERSION = YES; 438 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 439 | CLANG_WARN_EMPTY_BODY = YES; 440 | CLANG_WARN_ENUM_CONVERSION = YES; 441 | CLANG_WARN_INFINITE_RECURSION = YES; 442 | CLANG_WARN_INT_CONVERSION = YES; 443 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 444 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 445 | CLANG_WARN_UNREACHABLE_CODE = YES; 446 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 447 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 448 | COPY_PHASE_STRIP = NO; 449 | ENABLE_STRICT_OBJC_MSGSEND = YES; 450 | ENABLE_TESTABILITY = YES; 451 | GCC_C_LANGUAGE_STANDARD = gnu99; 452 | GCC_DYNAMIC_NO_PIC = NO; 453 | GCC_NO_COMMON_BLOCKS = YES; 454 | GCC_OPTIMIZATION_LEVEL = 0; 455 | GCC_PREPROCESSOR_DEFINITIONS = ( 456 | "DEBUG=1", 457 | "$(inherited)", 458 | ); 459 | GCC_SYMBOLS_PRIVATE_EXTERN = NO; 460 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 461 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 462 | GCC_WARN_UNDECLARED_SELECTOR = YES; 463 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 464 | GCC_WARN_UNUSED_FUNCTION = YES; 465 | GCC_WARN_UNUSED_VARIABLE = YES; 466 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 467 | ONLY_ACTIVE_ARCH = YES; 468 | SDKROOT = iphoneos; 469 | }; 470 | name = Debug; 471 | }; 472 | E148FDEE18DCB27B0021747E /* Release */ = { 473 | isa = XCBuildConfiguration; 474 | buildSettings = { 475 | ALWAYS_SEARCH_USER_PATHS = NO; 476 | CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; 477 | CLANG_CXX_LIBRARY = "libc++"; 478 | CLANG_ENABLE_MODULES = YES; 479 | CLANG_ENABLE_OBJC_ARC = YES; 480 | CLANG_WARN_BOOL_CONVERSION = YES; 481 | CLANG_WARN_CONSTANT_CONVERSION = YES; 482 | CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; 483 | CLANG_WARN_EMPTY_BODY = YES; 484 | CLANG_WARN_ENUM_CONVERSION = YES; 485 | CLANG_WARN_INFINITE_RECURSION = YES; 486 | CLANG_WARN_INT_CONVERSION = YES; 487 | CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; 488 | CLANG_WARN_SUSPICIOUS_MOVE = YES; 489 | CLANG_WARN_UNREACHABLE_CODE = YES; 490 | CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; 491 | "CODE_SIGN_IDENTITY[sdk=iphoneos*]" = "iPhone Developer"; 492 | COPY_PHASE_STRIP = YES; 493 | ENABLE_NS_ASSERTIONS = NO; 494 | ENABLE_STRICT_OBJC_MSGSEND = YES; 495 | GCC_C_LANGUAGE_STANDARD = gnu99; 496 | GCC_NO_COMMON_BLOCKS = YES; 497 | GCC_WARN_64_TO_32_BIT_CONVERSION = YES; 498 | GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; 499 | GCC_WARN_UNDECLARED_SELECTOR = YES; 500 | GCC_WARN_UNINITIALIZED_AUTOS = YES; 501 | GCC_WARN_UNUSED_FUNCTION = YES; 502 | GCC_WARN_UNUSED_VARIABLE = YES; 503 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 504 | SDKROOT = iphoneos; 505 | VALIDATE_PRODUCT = YES; 506 | }; 507 | name = Release; 508 | }; 509 | E148FDF018DCB27B0021747E /* Debug */ = { 510 | isa = XCBuildConfiguration; 511 | baseConfigurationReference = 96108743CC9E003B49F757A9 /* Pods-WechatPayDemo.debug.xcconfig */; 512 | buildSettings = { 513 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 514 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 515 | CLANG_CXX_LANGUAGE_STANDARD = "compiler-default"; 516 | CLANG_CXX_LIBRARY = "compiler-default"; 517 | DEVELOPMENT_TEAM = 4Y65NZLKET; 518 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 519 | GCC_PREFIX_HEADER = "WechatPayDemo/WechatPayDemo-Prefix.pch"; 520 | INFOPLIST_FILE = "WechatPayDemo/WechatPayDemo-Info.plist"; 521 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 522 | LIBRARY_SEARCH_PATHS = ( 523 | "$(inherited)", 524 | "$(PROJECT_DIR)/WechatPayDemo/WeChatSDK_64", 525 | ); 526 | PRODUCT_BUNDLE_IDENTIFIER = "Alvin.${PRODUCT_NAME:rfc1034identifier}"; 527 | PRODUCT_NAME = "$(TARGET_NAME)"; 528 | WRAPPER_EXTENSION = app; 529 | }; 530 | name = Debug; 531 | }; 532 | E148FDF118DCB27B0021747E /* Release */ = { 533 | isa = XCBuildConfiguration; 534 | baseConfigurationReference = 076A105D5C4695800F4BD61D /* Pods-WechatPayDemo.release.xcconfig */; 535 | buildSettings = { 536 | ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; 537 | ASSETCATALOG_COMPILER_LAUNCHIMAGE_NAME = LaunchImage; 538 | CLANG_CXX_LANGUAGE_STANDARD = "compiler-default"; 539 | CLANG_CXX_LIBRARY = "compiler-default"; 540 | DEVELOPMENT_TEAM = 4Y65NZLKET; 541 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 542 | GCC_PREFIX_HEADER = "WechatPayDemo/WechatPayDemo-Prefix.pch"; 543 | INFOPLIST_FILE = "WechatPayDemo/WechatPayDemo-Info.plist"; 544 | IPHONEOS_DEPLOYMENT_TARGET = 8.0; 545 | LIBRARY_SEARCH_PATHS = ( 546 | "$(inherited)", 547 | "$(PROJECT_DIR)/WechatPayDemo/WeChatSDK_64", 548 | ); 549 | PRODUCT_BUNDLE_IDENTIFIER = "Alvin.${PRODUCT_NAME:rfc1034identifier}"; 550 | PRODUCT_NAME = "$(TARGET_NAME)"; 551 | WRAPPER_EXTENSION = app; 552 | }; 553 | name = Release; 554 | }; 555 | E148FDF318DCB27B0021747E /* Debug */ = { 556 | isa = XCBuildConfiguration; 557 | buildSettings = { 558 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/WechatPayDemo.app/WechatPayDemo"; 559 | FRAMEWORK_SEARCH_PATHS = ( 560 | "$(SDKROOT)/Developer/Library/Frameworks", 561 | "$(inherited)", 562 | "$(DEVELOPER_FRAMEWORKS_DIR)", 563 | ); 564 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 565 | GCC_PREFIX_HEADER = "WechatPayDemo/WechatPayDemo-Prefix.pch"; 566 | GCC_PREPROCESSOR_DEFINITIONS = ( 567 | "DEBUG=1", 568 | "$(inherited)", 569 | ); 570 | INFOPLIST_FILE = "WechatPayDemoTests/WechatPayDemoTests-Info.plist"; 571 | PRODUCT_BUNDLE_IDENTIFIER = "Alvin.${PRODUCT_NAME:rfc1034identifier}"; 572 | PRODUCT_NAME = "$(TARGET_NAME)"; 573 | TEST_HOST = "$(BUNDLE_LOADER)"; 574 | WRAPPER_EXTENSION = xctest; 575 | }; 576 | name = Debug; 577 | }; 578 | E148FDF418DCB27B0021747E /* Release */ = { 579 | isa = XCBuildConfiguration; 580 | buildSettings = { 581 | BUNDLE_LOADER = "$(BUILT_PRODUCTS_DIR)/WechatPayDemo.app/WechatPayDemo"; 582 | FRAMEWORK_SEARCH_PATHS = ( 583 | "$(SDKROOT)/Developer/Library/Frameworks", 584 | "$(inherited)", 585 | "$(DEVELOPER_FRAMEWORKS_DIR)", 586 | ); 587 | GCC_PRECOMPILE_PREFIX_HEADER = YES; 588 | GCC_PREFIX_HEADER = "WechatPayDemo/WechatPayDemo-Prefix.pch"; 589 | INFOPLIST_FILE = "WechatPayDemoTests/WechatPayDemoTests-Info.plist"; 590 | PRODUCT_BUNDLE_IDENTIFIER = "Alvin.${PRODUCT_NAME:rfc1034identifier}"; 591 | PRODUCT_NAME = "$(TARGET_NAME)"; 592 | TEST_HOST = "$(BUNDLE_LOADER)"; 593 | WRAPPER_EXTENSION = xctest; 594 | }; 595 | name = Release; 596 | }; 597 | /* End XCBuildConfiguration section */ 598 | 599 | /* Begin XCConfigurationList section */ 600 | E148FDB818DCB27A0021747E /* Build configuration list for PBXProject "WechatPayDemo" */ = { 601 | isa = XCConfigurationList; 602 | buildConfigurations = ( 603 | E148FDED18DCB27B0021747E /* Debug */, 604 | E148FDEE18DCB27B0021747E /* Release */, 605 | ); 606 | defaultConfigurationIsVisible = 0; 607 | defaultConfigurationName = Release; 608 | }; 609 | E148FDEF18DCB27B0021747E /* Build configuration list for PBXNativeTarget "WechatPayDemo" */ = { 610 | isa = XCConfigurationList; 611 | buildConfigurations = ( 612 | E148FDF018DCB27B0021747E /* Debug */, 613 | E148FDF118DCB27B0021747E /* Release */, 614 | ); 615 | defaultConfigurationIsVisible = 0; 616 | defaultConfigurationName = Release; 617 | }; 618 | E148FDF218DCB27B0021747E /* Build configuration list for PBXNativeTarget "WechatPayDemoTests" */ = { 619 | isa = XCConfigurationList; 620 | buildConfigurations = ( 621 | E148FDF318DCB27B0021747E /* Debug */, 622 | E148FDF418DCB27B0021747E /* Release */, 623 | ); 624 | defaultConfigurationIsVisible = 0; 625 | defaultConfigurationName = Release; 626 | }; 627 | /* End XCConfigurationList section */ 628 | }; 629 | rootObject = E148FDB518DCB27A0021747E /* Project object */; 630 | } 631 | -------------------------------------------------------------------------------- /WechatPayDemo.xcodeproj/project.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /WechatPayDemo.xcodeproj/xcuserdata/alvin.xcuserdatad/xcschemes/WechatPayDemo.xcscheme: -------------------------------------------------------------------------------- 1 | 2 | 5 | 8 | 9 | 15 | 21 | 22 | 23 | 24 | 25 | 30 | 31 | 33 | 39 | 40 | 41 | 42 | 43 | 49 | 50 | 51 | 52 | 53 | 54 | 64 | 66 | 72 | 73 | 74 | 75 | 76 | 77 | 83 | 85 | 91 | 92 | 93 | 94 | 96 | 97 | 100 | 101 | 102 | -------------------------------------------------------------------------------- /WechatPayDemo.xcodeproj/xcuserdata/alvin.xcuserdatad/xcschemes/xcschememanagement.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | SchemeUserState 6 | 7 | WechatPayDemo.xcscheme 8 | 9 | orderHint 10 | 0 11 | 12 | 13 | SuppressBuildableAutocreation 14 | 15 | E148FDBC18DCB27A0021747E 16 | 17 | primary 18 | 19 | 20 | E148FDDD18DCB27B0021747E 21 | 22 | primary 23 | 24 | 25 | 26 | 27 | 28 | -------------------------------------------------------------------------------- /WechatPayDemo.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /WechatPayDemo/AppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.h 3 | // WechatPayDemo 4 | // 5 | // Created by Alvin on 3/22/14. 6 | // Copyright (c) 2014 Alvin. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "WXApi.h" 11 | 12 | @interface AppDelegate : UIResponder 13 | 14 | @property (strong, nonatomic) UIWindow *window; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /WechatPayDemo/AppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // AppDelegate.m 3 | // WechatPayDemo 4 | // 5 | // Created by Alvin on 3/22/14. 6 | // Copyright (c) 2014 Alvin. All rights reserved. 7 | // 8 | 9 | #import "AppDelegate.h" 10 | #import "Constant.h" 11 | 12 | /** 13 | * 微信开放平台申请得到的 appid, 需要同时添加在 URL schema 14 | */ 15 | NSString * const WXAppId = @"wxd930ea5d5a258f4f"; 16 | 17 | /** 18 | * 微信开放平台和商户约定的支付密钥 19 | * 20 | * 注意:不能hardcode在客户端,建议genSign这个过程由服务器端完成 21 | */ 22 | NSString * const WXAppKey = @"L8LrMqqeGRxST5reouB0K66CaYAWpqhAVsq7ggKkxHCOastWksvuX1uvmvQclxaHoYd3ElNBrNO2DHnnzgfVG9Qs473M3DTOZug5er46FhuGofumV8H2FVR9qkjSlC5K"; 23 | 24 | /** 25 | * 微信开放平台和商户约定的密钥 26 | * 27 | * 注意:不能hardcode在客户端,建议genSign这个过程由服务器端完成 28 | */ 29 | NSString * const WXAppSecret = @"db426a9829e4b49a0dcac7b4162da6b6"; 30 | 31 | /** 32 | * 微信开放平台和商户约定的支付密钥 33 | * 34 | * 注意:不能hardcode在客户端,建议genSign这个过程由服务器端完成 35 | */ 36 | NSString * const WXPartnerKey = @"8934e7d15453e97507ef794cf7b0519d"; 37 | 38 | /** 39 | * 微信公众平台商户模块生成的ID 40 | */ 41 | NSString * const WXPartnerId = @"1900000109"; 42 | 43 | @implementation AppDelegate 44 | 45 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 46 | { 47 | [WXApi registerApp:WXAppId]; 48 | 49 | return YES; 50 | } 51 | 52 | - (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url 53 | { 54 | return [WXApi handleOpenURL:url delegate:self]; 55 | } 56 | 57 | - (BOOL) application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation 58 | { 59 | return [WXApi handleOpenURL:url delegate:self]; 60 | } 61 | 62 | - (void)onResp:(BaseResp *)resp 63 | { 64 | if ([resp isKindOfClass:[PayResp class]]) { 65 | 66 | NSString *strTitle = [NSString stringWithFormat:@"支付结果"]; 67 | NSString *strMsg = [NSString stringWithFormat:@"errcode:%d", resp.errCode]; 68 | 69 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:strTitle 70 | message:strMsg 71 | delegate:self 72 | cancelButtonTitle:@"OK" 73 | otherButtonTitles:nil, nil]; 74 | [alert show]; 75 | 76 | [[NSNotificationCenter defaultCenter] postNotificationName:HUDDismissNotification object:nil userInfo:nil]; 77 | } 78 | } 79 | 80 | @end 81 | -------------------------------------------------------------------------------- /WechatPayDemo/Base.lproj/Main.storyboard: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | -------------------------------------------------------------------------------- /WechatPayDemo/CommonUtil.h: -------------------------------------------------------------------------------- 1 | // 2 | // CommonUtil.h 3 | // WechatPayDemo 4 | // 5 | // Created by Alvin on 3/22/14. 6 | // Copyright (c) 2014 Alvin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface CommonUtil : NSObject 12 | 13 | + (NSString *)md5:(NSString *)input; 14 | 15 | + (NSString *)sha1:(NSString *)input; 16 | 17 | + (NSString *)getIPAddress:(BOOL)preferIPv4; 18 | 19 | + (NSDictionary *)getIPAddresses; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /WechatPayDemo/CommonUtil.m: -------------------------------------------------------------------------------- 1 | // 2 | // CommonUtil.m 3 | // WechatPayDemo 4 | // 5 | // Created by Alvin on 3/22/14. 6 | // Copyright (c) 2014 Alvin. All rights reserved. 7 | // 8 | 9 | #import "CommonUtil.h" 10 | #import 11 | #include 12 | #include 13 | #include 14 | 15 | #define IOS_CELLULAR @"pdp_ip0" 16 | #define IOS_WIFI @"en0" 17 | #define IP_ADDR_IPv4 @"ipv4" 18 | #define IP_ADDR_IPv6 @"ipv6" 19 | 20 | @implementation CommonUtil 21 | 22 | + (NSString *)md5:(NSString *)input 23 | { 24 | const char *cStr = [input UTF8String]; 25 | unsigned char digest[16]; 26 | CC_MD5( cStr, strlen(cStr), digest ); // This is the md5 call 27 | 28 | NSMutableString *output = [NSMutableString stringWithCapacity:CC_MD5_DIGEST_LENGTH * 2]; 29 | 30 | for(int i = 0; i < CC_MD5_DIGEST_LENGTH; i++) 31 | [output appendFormat:@"%02x", digest[i]]; 32 | 33 | return output; 34 | } 35 | 36 | + (NSString *)sha1:(NSString *)input 37 | { 38 | const char *ptr = [input UTF8String]; 39 | 40 | int i =0; 41 | int len = strlen(ptr); 42 | Byte byteArray[len]; 43 | while (i!=len) 44 | { 45 | unsigned eachChar = *(ptr + i); 46 | unsigned low8Bits = eachChar & 0xFF; 47 | 48 | byteArray[i] = low8Bits; 49 | i++; 50 | } 51 | 52 | unsigned char digest[CC_SHA1_DIGEST_LENGTH]; 53 | 54 | CC_SHA1(byteArray, len, digest); 55 | 56 | NSMutableString *hex = [NSMutableString string]; 57 | for (int i=0; i<20; i++) 58 | [hex appendFormat:@"%02x", digest[i]]; 59 | 60 | NSString *immutableHex = [NSString stringWithString:hex]; 61 | 62 | return immutableHex; 63 | } 64 | 65 | + (NSString *)getIPAddress:(BOOL)preferIPv4 66 | { 67 | NSArray *searchArray = preferIPv4 ? 68 | @[ IOS_WIFI @"/" IP_ADDR_IPv4, IOS_WIFI @"/" IP_ADDR_IPv6, IOS_CELLULAR @"/" IP_ADDR_IPv4, IOS_CELLULAR @"/" IP_ADDR_IPv6 ] : 69 | @[ IOS_WIFI @"/" IP_ADDR_IPv6, IOS_WIFI @"/" IP_ADDR_IPv4, IOS_CELLULAR @"/" IP_ADDR_IPv6, IOS_CELLULAR @"/" IP_ADDR_IPv4 ] ; 70 | 71 | NSDictionary *addresses = [self getIPAddresses]; 72 | //NSLog(@"addresses: %@", addresses); 73 | 74 | __block NSString *address; 75 | [searchArray enumerateObjectsUsingBlock:^(NSString *key, NSUInteger idx, BOOL *stop) 76 | { 77 | address = addresses[key]; 78 | if(address) *stop = YES; 79 | } ]; 80 | return address ? address : @"0.0.0.0"; 81 | } 82 | 83 | + (NSDictionary *)getIPAddresses 84 | { 85 | NSMutableDictionary *addresses = [NSMutableDictionary dictionaryWithCapacity:8]; 86 | 87 | // retrieve the current interfaces - returns 0 on success 88 | struct ifaddrs *interfaces; 89 | if(!getifaddrs(&interfaces)) { 90 | // Loop through linked list of interfaces 91 | struct ifaddrs *interface; 92 | for(interface=interfaces; interface; interface=interface->ifa_next) { 93 | if(!(interface->ifa_flags & IFF_UP) || (interface->ifa_flags & IFF_LOOPBACK)) { 94 | continue; // deeply nested code harder to read 95 | } 96 | const struct sockaddr_in *addr = (const struct sockaddr_in*)interface->ifa_addr; 97 | if(addr && (addr->sin_family==AF_INET || addr->sin_family==AF_INET6)) { 98 | NSString *name = [NSString stringWithUTF8String:interface->ifa_name]; 99 | char addrBuf[INET6_ADDRSTRLEN]; 100 | if(inet_ntop(addr->sin_family, &addr->sin_addr, addrBuf, sizeof(addrBuf))) { 101 | NSString *key = [NSString stringWithFormat:@"%@/%@", name, addr->sin_family == AF_INET ? IP_ADDR_IPv4 : IP_ADDR_IPv6]; 102 | addresses[key] = [NSString stringWithUTF8String:addrBuf]; 103 | } 104 | } 105 | } 106 | // Free memory 107 | freeifaddrs(interfaces); 108 | } 109 | 110 | // The dictionary keys have the form "interface" "/" "ipv4 or ipv6" 111 | return [addresses count] ? addresses : nil; 112 | } 113 | 114 | @end 115 | -------------------------------------------------------------------------------- /WechatPayDemo/Constant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Constant.h 3 | // WechatPayDemo 4 | // 5 | // Created by Alvin on 3/22/14. 6 | // Copyright (c) 2014 Alvin. All rights reserved. 7 | // 8 | 9 | #ifndef WechatPayDemo_Constant_h 10 | #define WechatPayDemo_Constant_h 11 | 12 | /** 13 | * 微信开放平台申请得到的 appid, 同时需要添加在 URL schema 14 | */ 15 | extern NSString * const WXAppId; 16 | 17 | /** 18 | * 微信开放平台和商户约定的支付密钥 19 | * 20 | * 注意:不能hardcode在客户端,建议genSign这个过程由服务器端完成 21 | */ 22 | extern NSString * const WXAppKey; 23 | 24 | /** 25 | * 微信开放平台和商户约定的密钥 26 | * 27 | * 注意:不能hardcode在客户端,建议genSign这个过程由服务器端完成 28 | */ 29 | extern NSString * const WXAppSecret; 30 | 31 | /** 32 | * 微信开放平台和商户约定的支付密钥 33 | * 34 | * 注意:不能hardcode在客户端,建议genSign这个过程由服务器端完成 35 | */ 36 | extern NSString * const WXPartnerKey; 37 | 38 | /** 39 | * 微信公众平台商户模块生成的ID 40 | */ 41 | extern NSString * const WXPartnerId; 42 | 43 | /** 44 | * 隐藏 HUD notification 45 | */ 46 | extern NSString * const HUDDismissNotification; 47 | 48 | #endif 49 | -------------------------------------------------------------------------------- /WechatPayDemo/Images.xcassets/AppIcon.appiconset/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "idiom" : "iphone", 5 | "size" : "20x20", 6 | "scale" : "2x" 7 | }, 8 | { 9 | "idiom" : "iphone", 10 | "size" : "20x20", 11 | "scale" : "3x" 12 | }, 13 | { 14 | "idiom" : "iphone", 15 | "size" : "29x29", 16 | "scale" : "2x" 17 | }, 18 | { 19 | "idiom" : "iphone", 20 | "size" : "29x29", 21 | "scale" : "3x" 22 | }, 23 | { 24 | "idiom" : "iphone", 25 | "size" : "40x40", 26 | "scale" : "2x" 27 | }, 28 | { 29 | "idiom" : "iphone", 30 | "size" : "40x40", 31 | "scale" : "3x" 32 | }, 33 | { 34 | "idiom" : "iphone", 35 | "size" : "60x60", 36 | "scale" : "2x" 37 | }, 38 | { 39 | "idiom" : "iphone", 40 | "size" : "60x60", 41 | "scale" : "3x" 42 | } 43 | ], 44 | "info" : { 45 | "version" : 1, 46 | "author" : "xcode" 47 | } 48 | } -------------------------------------------------------------------------------- /WechatPayDemo/Images.xcassets/LaunchImage.launchimage/Contents.json: -------------------------------------------------------------------------------- 1 | { 2 | "images" : [ 3 | { 4 | "orientation" : "portrait", 5 | "idiom" : "iphone", 6 | "extent" : "full-screen", 7 | "minimum-system-version" : "7.0", 8 | "scale" : "2x" 9 | }, 10 | { 11 | "orientation" : "portrait", 12 | "idiom" : "iphone", 13 | "subtype" : "retina4", 14 | "extent" : "full-screen", 15 | "minimum-system-version" : "7.0", 16 | "scale" : "2x" 17 | } 18 | ], 19 | "info" : { 20 | "version" : 1, 21 | "author" : "xcode" 22 | } 23 | } -------------------------------------------------------------------------------- /WechatPayDemo/ViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.h 3 | // WechatPayDemo 4 | // 5 | // Created by Alvin on 3/22/14. 6 | // Copyright (c) 2014 Alvin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface ViewController : UIViewController 12 | 13 | @end 14 | -------------------------------------------------------------------------------- /WechatPayDemo/ViewController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ViewController.m 3 | // WechatPayDemo 4 | // 5 | // Created by Alvin on 3/22/14. 6 | // Copyright (c) 2014 Alvin. All rights reserved. 7 | // 8 | 9 | #import "ViewController.h" 10 | #import "Constant.h" 11 | #import 12 | #import "WXPayClient.h" 13 | 14 | NSString * const HUDDismissNotification = @"HUDDismissNotification"; 15 | 16 | @interface ViewController () 17 | 18 | @end 19 | 20 | @implementation ViewController 21 | 22 | - (void)dealloc 23 | { 24 | [[NSNotificationCenter defaultCenter] removeObserver:self]; 25 | } 26 | 27 | - (void)viewDidLoad 28 | { 29 | [super viewDidLoad]; 30 | // Do any additional setup after loading the view, typically from a nib. 31 | 32 | [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hideHUD) name:HUDDismissNotification object:nil]; 33 | } 34 | 35 | - (void)didReceiveMemoryWarning 36 | { 37 | [super didReceiveMemoryWarning]; 38 | // Dispose of any resources that can be recreated. 39 | } 40 | 41 | - (void)hideHUD 42 | { 43 | [MBProgressHUD hideAllHUDsForView:self.view animated:YES]; 44 | } 45 | 46 | #pragma mark - Action 47 | 48 | - (IBAction)pay:(id)sender 49 | { 50 | [MBProgressHUD hideAllHUDsForView:self.view animated:YES]; 51 | [MBProgressHUD showHUDAddedTo:self.view animated:YES]; 52 | 53 | [[WXPayClient shareInstance] payProduct]; 54 | } 55 | @end 56 | -------------------------------------------------------------------------------- /WechatPayDemo/WXPayClient.h: -------------------------------------------------------------------------------- 1 | // 2 | // WXPayClient.h 3 | // WechatPayDemo 4 | // 5 | // Created by Alvin on 3/22/14. 6 | // Copyright (c) 2014 Alvin. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "WXApi.h" 11 | 12 | @interface WXPayClient : NSObject 13 | 14 | + (instancetype)shareInstance; 15 | 16 | - (void)payProduct; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /WechatPayDemo/WXPayClient.m: -------------------------------------------------------------------------------- 1 | // 2 | // WXPayClient.m 3 | // WechatPayDemo 4 | // 5 | // Created by Alvin on 3/22/14. 6 | // Copyright (c) 2014 Alvin. All rights reserved. 7 | // 8 | 9 | #import "WXPayClient.h" 10 | #import 11 | #import "CommonUtil.h" 12 | #import "Constant.h" 13 | 14 | NSString *AccessTokenKey = @"access_token"; 15 | NSString *PrePayIdKey = @"prepayid"; 16 | NSString *errcodeKey = @"errcode"; 17 | NSString *errmsgKey = @"errmsg"; 18 | NSString *expiresInKey = @"expires_in"; 19 | 20 | @interface WXPayClient () 21 | 22 | @property (nonatomic, strong) ASIHTTPRequest *request; 23 | @property (nonatomic, copy) NSString *timeStamp; 24 | @property (nonatomic, copy) NSString *nonceStr; 25 | @property (nonatomic, copy) NSString *traceId; 26 | 27 | @end 28 | 29 | @implementation WXPayClient 30 | 31 | #pragma mark - Public 32 | 33 | + (instancetype)shareInstance 34 | { 35 | static WXPayClient *sharedClient = nil; 36 | static dispatch_once_t onceToken; 37 | dispatch_once(&onceToken, ^{ 38 | sharedClient = [[WXPayClient alloc] init]; 39 | }); 40 | return sharedClient; 41 | } 42 | 43 | - (void)payProduct 44 | { 45 | [self getAccessToken]; 46 | } 47 | 48 | #pragma mark - Generate params 49 | 50 | - (NSString *)genTimeStamp 51 | { 52 | return [NSString stringWithFormat:@"%.0f", [[NSDate date] timeIntervalSince1970]]; 53 | } 54 | 55 | /** 56 | * 注意:商户系统内部的订单号,32个字符内、可包含字母,确保在商户系统唯一 57 | */ 58 | - (NSString *)genNonceStr 59 | { 60 | return [CommonUtil md5:[NSString stringWithFormat:@"%d", arc4random() % 10000]]; 61 | } 62 | 63 | /** 64 | * 建议 traceid 字段包含用户信息及订单信息,方便后续对订单状态的查询和跟踪 65 | */ 66 | - (NSString *)genTraceId 67 | { 68 | return [NSString stringWithFormat:@"crestxu_%@", [self genTimeStamp]]; 69 | } 70 | 71 | - (NSString *)genOutTradNo 72 | { 73 | return [CommonUtil md5:[NSString stringWithFormat:@"%d", arc4random() % 10000]]; 74 | } 75 | 76 | - (NSString *)genPackage 77 | { 78 | // 构造参数列表 79 | NSMutableDictionary *params = [NSMutableDictionary dictionary]; 80 | [params setObject:@"WX" forKey:@"bank_type"]; 81 | [params setObject:@"千足金箍棒" forKey:@"body"]; 82 | [params setObject:@"1" forKey:@"fee_type"]; 83 | [params setObject:@"UTF-8" forKey:@"input_charset"]; 84 | [params setObject:@"http://weixin.qq.com" forKey:@"notify_url"]; 85 | [params setObject:[self genOutTradNo] forKey:@"out_trade_no"]; 86 | [params setObject:WXPartnerId forKey:@"partner"]; 87 | [params setObject:[CommonUtil getIPAddress:YES] forKey:@"spbill_create_ip"]; 88 | [params setObject:@"1" forKey:@"total_fee"]; // 1 == ¥0.01 89 | 90 | NSArray *keys = [params allKeys]; 91 | NSArray *sortedKeys = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { 92 | return [obj1 compare:obj2 options:NSNumericSearch]; 93 | }]; 94 | 95 | // 生成 packageSign 96 | NSMutableString *package = [NSMutableString string]; 97 | for (NSString *key in sortedKeys) { 98 | [package appendString:key]; 99 | [package appendString:@"="]; 100 | [package appendString:[params objectForKey:key]]; 101 | [package appendString:@"&"]; 102 | } 103 | 104 | [package appendString:@"key="]; 105 | [package appendString:WXPartnerKey]; // 注意:不能hardcode在客户端,建议genPackage这个过程都由服务器端完成 106 | 107 | // 进行md5摘要前,params内容为原始内容,未经过url encode处理 108 | NSString *packageSign = [[CommonUtil md5:[package copy]] uppercaseString]; 109 | package = nil; 110 | 111 | // 生成 packageParamsString 112 | NSString *value = nil; 113 | package = [NSMutableString string]; 114 | for (NSString *key in sortedKeys) { 115 | [package appendString:key]; 116 | [package appendString:@"="]; 117 | value = [params objectForKey:key]; 118 | 119 | // 对所有键值对中的 value 进行 urlencode 转码 120 | value = (NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault, (CFStringRef)value, nil, (CFStringRef)@"!*'&=();:@+$,/?%#[]", kCFStringEncodingUTF8)); 121 | 122 | [package appendString:value]; 123 | [package appendString:@"&"]; 124 | } 125 | NSString *packageParamsString = [package substringWithRange:NSMakeRange(0, package.length - 1)]; 126 | 127 | NSString *result = [NSString stringWithFormat:@"%@&sign=%@", packageParamsString, packageSign]; 128 | 129 | NSLog(@"--- Package: %@", result); 130 | 131 | return result; 132 | } 133 | 134 | - (NSString *)genSign:(NSDictionary *)signParams 135 | { 136 | // 排序 137 | NSArray *keys = [signParams allKeys]; 138 | NSArray *sortedKeys = [keys sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) { 139 | return [obj1 compare:obj2 options:NSNumericSearch]; 140 | }]; 141 | 142 | // 生成 143 | NSMutableString *sign = [NSMutableString string]; 144 | for (NSString *key in sortedKeys) { 145 | [sign appendString:key]; 146 | [sign appendString:@"="]; 147 | [sign appendString:[signParams objectForKey:key]]; 148 | [sign appendString:@"&"]; 149 | } 150 | NSString *signString = [[sign copy] substringWithRange:NSMakeRange(0, sign.length - 1)]; 151 | 152 | NSString *result = [CommonUtil sha1:signString]; 153 | NSLog(@"--- Gen sign: %@", result); 154 | return result; 155 | } 156 | 157 | - (NSMutableData *)getProductArgs 158 | { 159 | self.timeStamp = [self genTimeStamp]; 160 | self.nonceStr = [self genNonceStr]; // traceId 由开发者自定义,可用于订单的查询与跟踪,建议根据支付用户信息生成此id 161 | self.traceId = [self genTraceId]; 162 | 163 | NSMutableDictionary *params = [NSMutableDictionary dictionary]; 164 | [params setObject:WXAppId forKey:@"appid"]; 165 | [params setObject:WXAppKey forKey:@"appkey"]; 166 | [params setObject:self.timeStamp forKey:@"noncestr"]; 167 | [params setObject:self.timeStamp forKey:@"timestamp"]; 168 | [params setObject:self.traceId forKey:@"traceid"]; 169 | [params setObject:[self genPackage] forKey:@"package"]; 170 | [params setObject:[self genSign:params] forKey:@"app_signature"]; 171 | [params setObject:@"sha1" forKey:@"sign_method"]; 172 | 173 | NSError *error = nil; 174 | NSData *jsonData = [NSJSONSerialization dataWithJSONObject:params options:NSJSONWritingPrettyPrinted error: &error]; 175 | NSLog(@"--- ProductArgs: %@", [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]); 176 | return [NSMutableData dataWithData:jsonData]; 177 | } 178 | 179 | #pragma mark - 主体流程 180 | 181 | - (void)getAccessToken 182 | { 183 | NSString *getAccessTokenUrl = [NSString stringWithFormat:@"https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=%@&secret=%@", WXAppId, WXAppSecret]; 184 | 185 | NSLog(@"--- GetAccessTokenUrl: %@", getAccessTokenUrl); 186 | 187 | self.request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:getAccessTokenUrl]]; 188 | 189 | __weak WXPayClient *weakSelf = self; 190 | __weak ASIHTTPRequest *weakRequest = self.request; 191 | 192 | [self.request setCompletionBlock:^{ 193 | NSError *error = nil; 194 | NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[weakRequest responseData] 195 | options:kNilOptions 196 | error:&error]; 197 | if (error) { 198 | [weakSelf showAlertWithTitle:@"错误" msg:@"获取 AccessToken 失败"]; 199 | return; 200 | } else { 201 | NSLog(@"--- %@", [weakRequest responseString]); 202 | } 203 | 204 | NSString *accessToken = dict[AccessTokenKey]; 205 | if (accessToken) { 206 | NSLog(@"--- AccessToken: %@", accessToken); 207 | 208 | __strong WXPayClient *strongSelf = weakSelf; 209 | [strongSelf getPrepayId:accessToken]; 210 | } else { 211 | NSString *strMsg = [NSString stringWithFormat:@"errcode: %@, errmsg:%@", dict[errcodeKey], dict[errmsgKey]]; 212 | [weakSelf showAlertWithTitle:@"错误" msg:strMsg]; 213 | } 214 | }]; 215 | 216 | [self.request setFailedBlock:^{ 217 | [weakSelf showAlertWithTitle:@"错误" msg:@"获取 AccessToken 失败"]; 218 | }]; 219 | [self.request startAsynchronous]; 220 | } 221 | 222 | - (void)getPrepayId:(NSString *)accessToken 223 | { 224 | NSString *getPrepayIdUrl = [NSString stringWithFormat:@"https://api.weixin.qq.com/pay/genprepay?access_token=%@", accessToken]; 225 | 226 | NSLog(@"--- GetPrepayIdUrl: %@", getPrepayIdUrl); 227 | 228 | NSMutableData *postData = [self getProductArgs]; 229 | 230 | // 文档: 详细的订单数据放在 PostData 中,格式为 json 231 | self.request = [ASIHTTPRequest requestWithURL:[NSURL URLWithString:getPrepayIdUrl]]; 232 | [self.request addRequestHeader:@"Content-Type" value:@"application/json"]; 233 | [self.request addRequestHeader:@"Accept" value:@"application/json"]; 234 | [self.request setRequestMethod:@"POST"]; 235 | [self.request setPostBody:postData]; 236 | 237 | __weak WXPayClient *weakSelf = self; 238 | __weak ASIHTTPRequest *weakRequest = self.request; 239 | 240 | [self.request setCompletionBlock:^{ 241 | NSError *error = nil; 242 | NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:[weakRequest responseData] 243 | options:kNilOptions 244 | error:&error]; 245 | 246 | if (error) { 247 | [weakSelf showAlertWithTitle:@"错误" msg:@"获取 PrePayId 失败"]; 248 | return; 249 | } else { 250 | NSLog(@"--- %@", [weakRequest responseString]); 251 | } 252 | 253 | NSString *prePayId = dict[PrePayIdKey]; 254 | if (prePayId) { 255 | NSLog(@"--- PrePayId: %@", prePayId); 256 | 257 | // 调起微信支付 258 | PayReq *request = [[PayReq alloc] init]; 259 | request.partnerId = WXPartnerId; 260 | request.prepayId = prePayId; 261 | request.package = @"Sign=WXPay"; // 文档为 `Request.package = _package;` , 但如果填写上面生成的 `package` 将不能支付成功 262 | request.nonceStr = weakSelf.nonceStr; 263 | request.timeStamp = [weakSelf.timeStamp intValue]; 264 | 265 | // 构造参数列表 266 | NSMutableDictionary *params = [NSMutableDictionary dictionary]; 267 | [params setObject:WXAppId forKey:@"appid"]; 268 | [params setObject:WXAppKey forKey:@"appkey"]; 269 | [params setObject:request.nonceStr forKey:@"noncestr"]; 270 | [params setObject:request.package forKey:@"package"]; 271 | [params setObject:request.partnerId forKey:@"partnerid"]; 272 | [params setObject:request.prepayId forKey:@"prepayid"]; 273 | [params setObject:weakSelf.timeStamp forKey:@"timestamp"]; 274 | request.sign = [weakSelf genSign:params]; 275 | 276 | // 在支付之前,如果应用没有注册到微信,应该先调用 [WXApi registerApp:appId] 将应用注册到微信 277 | [WXApi sendReq:request]; 278 | } else { 279 | NSString *strMsg = [NSString stringWithFormat:@"errcode: %@, errmsg:%@", dict[errcodeKey], dict[errmsgKey]]; 280 | [weakSelf showAlertWithTitle:@"错误" msg:strMsg]; 281 | } 282 | }]; 283 | [self.request setFailedBlock:^{ 284 | [weakSelf showAlertWithTitle:@"错误" msg:@"获取 PrePayId 失败"]; 285 | }]; 286 | [self.request startAsynchronous]; 287 | } 288 | 289 | #pragma mark - Alert 290 | 291 | - (void)showAlertWithTitle:(NSString *)title msg:(NSString *)msg 292 | { 293 | UIAlertView *alert = [[UIAlertView alloc] initWithTitle:title 294 | message:msg 295 | delegate:self 296 | cancelButtonTitle:@"OK" 297 | otherButtonTitles:nil, nil]; 298 | [alert show]; 299 | [[NSNotificationCenter defaultCenter] postNotificationName:HUDDismissNotification object:nil userInfo:nil]; 300 | } 301 | 302 | @end 303 | -------------------------------------------------------------------------------- /WechatPayDemo/WeChatSDK_64/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 | -------------------------------------------------------------------------------- /WechatPayDemo/WeChatSDK_64/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 | #pragma mark - SendAuthReq 132 | /*! @brief 第三方程序向微信终端请求认证的消息结构 133 | * 134 | * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数, 135 | * 向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 136 | * @see SendAuthResp 137 | */ 138 | @interface SendAuthReq : BaseReq 139 | /** 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。微信终端处理完后会向第三方程序发送一个处理结果。 140 | * @see SendAuthResp 141 | * @note scope字符串长度不能超过1K 142 | */ 143 | @property (nonatomic, retain) NSString* scope; 144 | /** 第三方程序本身用来标识其请求的唯一性,最后跳转回第三方程序时,由微信终端回传。 145 | * @note state字符串长度不能超过1K 146 | */ 147 | @property (nonatomic, retain) NSString* state; 148 | @end 149 | 150 | 151 | 152 | #pragma mark - SendAuthResp 153 | /*! @brief 微信处理完第三方程序的认证和权限申请后向第三方程序回送的处理结果。 154 | * 155 | * 第三方程序要向微信申请认证,并请求某些权限,需要调用WXApi的sendReq成员函数,向微信终端发送一个SendAuthReq消息结构。 156 | * 微信终端处理完后会向第三方程序发送一个SendAuthResp。 157 | * @see onResp 158 | */ 159 | @interface SendAuthResp : BaseResp 160 | @property (nonatomic, retain) NSString* code; 161 | /** 第三方程序发送时用来标识其请求的唯一性的标志,由第三方程序调用sendReq时传入,由微信终端回传 162 | * @note state字符串长度不能超过1K 163 | */ 164 | @property (nonatomic, retain) NSString* state; 165 | @property (nonatomic, retain) NSString* lang; 166 | @property (nonatomic, retain) NSString* country; 167 | @end 168 | 169 | 170 | 171 | #pragma mark - SendMessageToWXReq 172 | /*! @brief 第三方程序发送消息至微信终端程序的消息结构体 173 | * 174 | * 第三方程序向微信发送信息需要传入SendMessageToWXReq结构体,信息类型包括文本消息和多媒体消息, 175 | * 分别对应于text和message成员。调用该方法后,微信处理完信息会向第三方程序发送一个处理结果。 176 | * @see SendMessageToWXResp 177 | */ 178 | @interface SendMessageToWXReq : BaseReq 179 | /** 发送消息的文本内容 180 | * @note 文本长度必须大于0且小于10K 181 | */ 182 | @property (nonatomic, retain) NSString* text; 183 | /** 发送消息的多媒体内容 184 | * @see WXMediaMessage 185 | */ 186 | @property (nonatomic, retain) WXMediaMessage* message; 187 | /** 发送消息的类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ 188 | @property (nonatomic, assign) BOOL bText; 189 | /** 发送的目标场景,可以选择发送到会话(WXSceneSession)或者朋友圈(WXSceneTimeline)。 默认发送到会话。 190 | * @see WXScene 191 | */ 192 | @property (nonatomic, assign) int scene; 193 | 194 | @end 195 | 196 | 197 | 198 | #pragma mark - SendMessageToWXResp 199 | /*! @brief 微信终端向第三方程序返回的SendMessageToWXReq处理结果。 200 | * 201 | * 第三方程序向微信终端发送SendMessageToWXReq后,微信发送回来的处理结果,该结果用SendMessageToWXResp表示。 202 | */ 203 | @interface SendMessageToWXResp : BaseResp 204 | @property(nonatomic, retain) NSString* lang; 205 | @property(nonatomic, retain) NSString* country; 206 | @end 207 | 208 | 209 | #pragma mark - GetMessageFromWXReq 210 | /*! @brief 微信终端向第三方程序请求提供内容的消息结构体。 211 | * 212 | * 微信终端向第三方程序请求提供内容,微信终端会向第三方程序发送GetMessageFromWXReq消息结构体, 213 | * 需要第三方程序调用sendResp返回一个GetMessageFromWXResp消息结构体。 214 | */ 215 | @interface GetMessageFromWXReq : BaseReq 216 | @property (nonatomic, retain) NSString* lang; 217 | @property (nonatomic, retain) NSString* country; 218 | @end 219 | 220 | 221 | 222 | #pragma mark - GetMessageFromWXResp 223 | /*! @brief 微信终端向第三方程序请求提供内容,第三方程序向微信终端返回的消息结构体。 224 | * 225 | * 微信终端向第三方程序请求提供内容,第三方程序调用sendResp向微信终端返回一个GetMessageFromWXResp消息结构体。 226 | */ 227 | @interface GetMessageFromWXResp : BaseResp 228 | /** 向微信终端提供的文本内容 229 | @note 文本长度必须大于0且小于10K 230 | */ 231 | @property (nonatomic, retain) NSString* text; 232 | /** 向微信终端提供的多媒体内容。 233 | * @see WXMediaMessage 234 | */ 235 | @property (nonatomic, retain) WXMediaMessage* message; 236 | /** 向微信终端提供内容的消息类型,包括文本消息和多媒体消息两种,两者只能选择其一,不能同时发送文本和多媒体消息 */ 237 | @property (nonatomic, assign) BOOL bText; 238 | @end 239 | 240 | 241 | 242 | #pragma mark - ShowMessageFromWXReq 243 | /*! @brief 微信通知第三方程序,要求第三方程序显示的消息结构体。 244 | * 245 | * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 246 | * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 247 | */ 248 | @interface ShowMessageFromWXReq : BaseReq 249 | /** 微信终端向第三方程序发送的要求第三方程序处理的多媒体内容 250 | * @see WXMediaMessage 251 | */ 252 | @property (nonatomic, retain) WXMediaMessage* message; 253 | @property (nonatomic, retain) NSString* lang; 254 | @property (nonatomic, retain) NSString* country; 255 | @end 256 | 257 | 258 | 259 | #pragma mark - ShowMessageFromWXResp 260 | /*! @brief 微信通知第三方程序,要求第三方程序显示或处理某些消息,第三方程序处理完后向微信终端发送的处理结果。 261 | * 262 | * 微信需要通知第三方程序显示或处理某些内容时,会向第三方程序发送ShowMessageFromWXReq消息结构体。 263 | * 第三方程序处理完内容后调用sendResp向微信终端发送ShowMessageFromWXResp。 264 | */ 265 | @interface ShowMessageFromWXResp : BaseResp 266 | @end 267 | 268 | 269 | 270 | #pragma mark - LaunchFromWXReq 271 | /*! @brief 微信终端打开第三方程序携带的消息结构体 272 | * 273 | * 微信向第三方发送的结构体,第三方不需要返回 274 | */ 275 | @interface LaunchFromWXReq : BaseReq 276 | @property (nonatomic, retain) WXMediaMessage* message; 277 | @property (nonatomic, retain) NSString* lang; 278 | @property (nonatomic, retain) NSString* country; 279 | @end 280 | 281 | #pragma mark - OpenTempSessionReq 282 | /* ! @brief 第三方通知微信,打开临时会话 283 | * 284 | * 第三方通知微信,打开临时会话 285 | */ 286 | @interface OpenTempSessionReq : BaseReq 287 | /** 需要打开的用户名 288 | * @attention 长度不能超过512字节 289 | */ 290 | @property (nonatomic, retain) NSString* username; 291 | /** 开发者自定义参数,拉起临时会话后会发给开发者后台,可以用于识别场景 292 | * @attention 长度不能超过32位 293 | */ 294 | @property (nonatomic, retain) NSString* sessionFrom; 295 | @end 296 | 297 | #pragma mark - OpenTempSessionResp 298 | /*! @brief 微信终端向第三方程序返回的OpenTempSessionReq处理结果。 299 | * 300 | * 第三方程序向微信终端发送OpenTempSessionReq后,微信发送回来的处理结果,该结果用OpenTempSessionResp表示。 301 | */ 302 | @interface OpenTempSessionResp : BaseResp 303 | 304 | @end 305 | 306 | #pragma mark - OpenWebviewReq 307 | /* ! @brief 第三方通知微信启动内部浏览器,打开指定网页 308 | * 309 | * 第三方通知微信启动内部浏览器,打开指定Url对应的网页 310 | */ 311 | @interface OpenWebviewReq : BaseReq 312 | /** 需要打开的网页对应的Url 313 | * @attention 长度不能超过1024 314 | */ 315 | @property(nonatomic,retain)NSString* url; 316 | 317 | @end 318 | 319 | #pragma mark - OpenWebviewResp 320 | /*! @brief 微信终端向第三方程序返回的OpenWebviewReq处理结果 321 | * 322 | * 第三方程序向微信终端发送OpenWebviewReq后,微信发送回来的处理结果,该结果用OpenWebviewResp表示 323 | */ 324 | @interface OpenWebviewResp : BaseResp 325 | 326 | @end 327 | 328 | #pragma mark - OpenRankListReq 329 | /* ! @brief 第三方通知微信,打开硬件排行榜 330 | * 331 | * 第三方通知微信,打开硬件排行榜 332 | */ 333 | @interface OpenRankListReq : BaseReq 334 | 335 | @end 336 | 337 | #pragma mark - OpenRanklistResp 338 | /*! @brief 微信终端向第三方程序返回的OpenRankListReq处理结果。 339 | * 340 | * 第三方程序向微信终端发送OpenRankListReq后,微信发送回来的处理结果,该结果用OpenRankListResp表示。 341 | */ 342 | @interface OpenRankListResp : BaseResp 343 | 344 | @end 345 | 346 | #pragma mark - JumpToBizProfileReq 347 | /* ! @brief 第三方通知微信,打开指定微信号profile页面 348 | * 349 | * 第三方通知微信,打开指定微信号profile页面 350 | */ 351 | @interface JumpToBizProfileReq : BaseReq 352 | /** 跳转到该公众号的profile 353 | * @attention 长度不能超过512字节 354 | */ 355 | @property (nonatomic, retain) NSString* username; 356 | /** 如果用户加了该公众号为好友,extMsg会上传到服务器 357 | * @attention 长度不能超过1024字节 358 | */ 359 | @property (nonatomic, retain) NSString* extMsg; 360 | /** 361 | * 跳转的公众号类型 362 | * @see WXBizProfileType 363 | */ 364 | @property (nonatomic, assign) int profileType; 365 | @end 366 | 367 | 368 | 369 | #pragma mark - JumpToBizWebviewReq 370 | /* ! @brief 第三方通知微信,打开指定usrname的profile网页版 371 | * 372 | */ 373 | @interface JumpToBizWebviewReq : BaseReq 374 | /** 跳转的网页类型,目前只支持广告页 375 | * @see WXMPWebviewType 376 | */ 377 | @property(nonatomic, assign) int webType; 378 | /** 跳转到该公众号的profile网页版 379 | * @attention 长度不能超过512字节 380 | */ 381 | @property(nonatomic, retain) NSString* tousrname; 382 | /** 如果用户加了该公众号为好友,extMsg会上传到服务器 383 | * @attention 长度不能超过1024字节 384 | */ 385 | @property(nonatomic, retain) NSString* extMsg; 386 | 387 | @end 388 | 389 | #pragma mark - WXCardItem 390 | 391 | @interface WXCardItem : NSObject 392 | /** 卡id 393 | * @attention 长度不能超过1024字节 394 | */ 395 | @property (nonatomic,retain) NSString* cardId; 396 | /** ext信息 397 | * @attention 长度不能超过2024字节 398 | * 具体见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说明 399 | */ 400 | @property (nonatomic,retain) NSString* extMsg; 401 | /** 402 | * @attention 卡的状态,req不需要填。resp:0为未添加,1为已添加。 403 | */ 404 | @property (nonatomic,assign) UInt32 cardState; 405 | @end; 406 | 407 | #pragma mark - AddCardToWXCardPackageReq 408 | /* ! @brief 请求添加卡券至微信卡包 409 | * 410 | */ 411 | 412 | @interface AddCardToWXCardPackageReq : BaseReq 413 | /** 卡列表 414 | * @attention 个数不能超过40个 类型WXCardItem 415 | */ 416 | @property (nonatomic,retain) NSArray* cardAry; 417 | 418 | @end 419 | 420 | 421 | #pragma mark - AddCardToWXCardPackageResp 422 | /** ! @brief 微信返回第三方添加卡券结果 423 | * 424 | */ 425 | 426 | @interface AddCardToWXCardPackageResp : BaseResp 427 | /** 卡列表 428 | * @attention 个数不能超过40个 类型WXCardItem 429 | */ 430 | @property (nonatomic,retain) NSArray* cardAry; 431 | @end 432 | 433 | #pragma mark - WXMediaMessage 434 | 435 | /*! @brief 多媒体消息结构体 436 | * 437 | * 用于微信终端和第三方程序之间传递消息的多媒体消息内容 438 | */ 439 | @interface WXMediaMessage : NSObject 440 | 441 | +(WXMediaMessage *) message; 442 | 443 | /** 标题 444 | * @note 长度不能超过512字节 445 | */ 446 | @property (nonatomic, retain) NSString *title; 447 | /** 描述内容 448 | * @note 长度不能超过1K 449 | */ 450 | @property (nonatomic, retain) NSString *description; 451 | /** 缩略图数据 452 | * @note 大小不能超过32K 453 | */ 454 | @property (nonatomic, retain) NSData *thumbData; 455 | /** 456 | * @note 长度不能超过64字节 457 | */ 458 | @property (nonatomic, retain) NSString *mediaTagName; 459 | /** 460 | * 461 | */ 462 | @property (nonatomic, retain) NSString *messageExt; 463 | @property (nonatomic, retain) NSString *messageAction; 464 | /** 465 | * 多媒体数据对象,可以为WXImageObject,WXMusicObject,WXVideoObject,WXWebpageObject等。 466 | */ 467 | @property (nonatomic, retain) id mediaObject; 468 | 469 | /*! @brief 设置消息缩略图的方法 470 | * 471 | * @param image 缩略图 472 | * @note 大小不能超过32K 473 | */ 474 | - (void) setThumbImage:(UIImage *)image; 475 | 476 | @end 477 | 478 | 479 | 480 | #pragma mark - WXImageObject 481 | /*! @brief 多媒体消息中包含的图片数据对象 482 | * 483 | * 微信终端和第三方程序之间传递消息中包含的图片数据对象。 484 | * @note imageData和imageUrl成员不能同时为空 485 | * @see WXMediaMessage 486 | */ 487 | @interface WXImageObject : NSObject 488 | /*! @brief 返回一个WXImageObject对象 489 | * 490 | * @note 返回的WXImageObject对象是自动释放的 491 | */ 492 | +(WXImageObject *) object; 493 | 494 | /** 图片真实数据内容 495 | * @note 大小不能超过10M 496 | */ 497 | @property (nonatomic, retain) NSData *imageData; 498 | /** 图片url 499 | * @note 长度不能超过10K 500 | */ 501 | @property (nonatomic, retain) NSString *imageUrl; 502 | 503 | @end 504 | 505 | 506 | #pragma mark - WXMusicObject 507 | /*! @brief 多媒体消息中包含的音乐数据对象 508 | * 509 | * 微信终端和第三方程序之间传递消息中包含的音乐数据对象。 510 | * @note musicUrl和musicLowBandUrl成员不能同时为空。 511 | * @see WXMediaMessage 512 | */ 513 | @interface WXMusicObject : NSObject 514 | /*! @brief 返回一个WXMusicObject对象 515 | * 516 | * @note 返回的WXMusicObject对象是自动释放的 517 | */ 518 | +(WXMusicObject *) object; 519 | 520 | /** 音乐网页的url地址 521 | * @note 长度不能超过10K 522 | */ 523 | @property (nonatomic, retain) NSString *musicUrl; 524 | /** 音乐lowband网页的url地址 525 | * @note 长度不能超过10K 526 | */ 527 | @property (nonatomic, retain) NSString *musicLowBandUrl; 528 | /** 音乐数据url地址 529 | * @note 长度不能超过10K 530 | */ 531 | @property (nonatomic, retain) NSString *musicDataUrl; 532 | 533 | /**音乐lowband数据url地址 534 | * @note 长度不能超过10K 535 | */ 536 | @property (nonatomic, retain) NSString *musicLowBandDataUrl; 537 | 538 | @end 539 | 540 | 541 | 542 | #pragma mark - WXVideoObject 543 | /*! @brief 多媒体消息中包含的视频数据对象 544 | * 545 | * 微信终端和第三方程序之间传递消息中包含的视频数据对象。 546 | * @note videoUrl和videoLowBandUrl不能同时为空。 547 | * @see WXMediaMessage 548 | */ 549 | @interface WXVideoObject : NSObject 550 | /*! @brief 返回一个WXVideoObject对象 551 | * 552 | * @note 返回的WXVideoObject对象是自动释放的 553 | */ 554 | +(WXVideoObject *) object; 555 | 556 | /** 视频网页的url地址 557 | * @note 长度不能超过10K 558 | */ 559 | @property (nonatomic, retain) NSString *videoUrl; 560 | /** 视频lowband网页的url地址 561 | * @note 长度不能超过10K 562 | */ 563 | @property (nonatomic, retain) NSString *videoLowBandUrl; 564 | 565 | @end 566 | 567 | 568 | 569 | #pragma mark - WXWebpageObject 570 | /*! @brief 多媒体消息中包含的网页数据对象 571 | * 572 | * 微信终端和第三方程序之间传递消息中包含的网页数据对象。 573 | * @see WXMediaMessage 574 | */ 575 | @interface WXWebpageObject : NSObject 576 | /*! @brief 返回一个WXWebpageObject对象 577 | * 578 | * @note 返回的WXWebpageObject对象是自动释放的 579 | */ 580 | +(WXWebpageObject *) object; 581 | 582 | /** 网页的url地址 583 | * @note 不能为空且长度不能超过10K 584 | */ 585 | @property (nonatomic, retain) NSString *webpageUrl; 586 | 587 | @end 588 | 589 | 590 | 591 | #pragma mark - WXAppExtendObject 592 | /*! @brief 多媒体消息中包含的App扩展数据对象 593 | * 594 | * 第三方程序向微信终端发送包含WXAppExtendObject的多媒体消息, 595 | * 微信需要处理该消息时,会调用该第三方程序来处理多媒体消息内容。 596 | * @note url,extInfo和fileData不能同时为空 597 | * @see WXMediaMessage 598 | */ 599 | @interface WXAppExtendObject : NSObject 600 | /*! @brief 返回一个WXAppExtendObject对象 601 | * 602 | * @note 返回的WXAppExtendObject对象是自动释放的 603 | */ 604 | +(WXAppExtendObject *) object; 605 | 606 | /** 若第三方程序不存在,微信终端会打开该url所指的App下载地址 607 | * @note 长度不能超过10K 608 | */ 609 | @property (nonatomic, retain) NSString *url; 610 | /** 第三方程序自定义简单数据,微信终端会回传给第三方程序处理 611 | * @note 长度不能超过2K 612 | */ 613 | @property (nonatomic, retain) NSString *extInfo; 614 | /** App文件数据,该数据发送给微信好友,微信好友需要点击后下载数据,微信终端会回传给第三方程序处理 615 | * @note 大小不能超过10M 616 | */ 617 | @property (nonatomic, retain) NSData *fileData; 618 | 619 | @end 620 | 621 | 622 | 623 | #pragma mark - WXEmoticonObject 624 | /*! @brief 多媒体消息中包含的表情数据对象 625 | * 626 | * 微信终端和第三方程序之间传递消息中包含的表情数据对象。 627 | * @see WXMediaMessage 628 | */ 629 | @interface WXEmoticonObject : NSObject 630 | 631 | /*! @brief 返回一个WXEmoticonObject对象 632 | * 633 | * @note 返回的WXEmoticonObject对象是自动释放的 634 | */ 635 | +(WXEmoticonObject *) object; 636 | 637 | /** 表情真实数据内容 638 | * @note 大小不能超过10M 639 | */ 640 | @property (nonatomic, retain) NSData *emoticonData; 641 | 642 | @end 643 | 644 | 645 | 646 | #pragma mark - WXFileObject 647 | /*! @brief 多媒体消息中包含的文件数据对象 648 | * 649 | * @see WXMediaMessage 650 | */ 651 | @interface WXFileObject : NSObject 652 | 653 | /*! @brief 返回一个WXFileObject对象 654 | * 655 | * @note 返回的WXFileObject对象是自动释放的 656 | */ 657 | +(WXFileObject *) object; 658 | 659 | /** 文件后缀名 660 | * @note 长度不超过64字节 661 | */ 662 | @property (nonatomic, retain) NSString *fileExtension; 663 | 664 | /** 文件真实数据内容 665 | * @note 大小不能超过10M 666 | */ 667 | @property (nonatomic, retain) NSData *fileData; 668 | 669 | @end 670 | -------------------------------------------------------------------------------- /WechatPayDemo/WeChatSDK_64/libWeChatSDK.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gbammc/WechatPayDemo/667d0a4d6052ce88e7b5fdd20362f857e6fd0e74/WechatPayDemo/WeChatSDK_64/libWeChatSDK.a -------------------------------------------------------------------------------- /WechatPayDemo/WechatPayDemo-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIdentifier 12 | $(PRODUCT_BUNDLE_IDENTIFIER) 13 | CFBundleInfoDictionaryVersion 14 | 6.0 15 | CFBundleName 16 | ${PRODUCT_NAME} 17 | CFBundlePackageType 18 | APPL 19 | CFBundleShortVersionString 20 | 1.0 21 | CFBundleSignature 22 | ???? 23 | CFBundleURLTypes 24 | 25 | 26 | CFBundleTypeRole 27 | Viewer 28 | CFBundleURLName 29 | weixin 30 | CFBundleURLSchemes 31 | 32 | wxd930ea5d5a258f4f 33 | 34 | 35 | 36 | CFBundleVersion 37 | 1.0 38 | LSRequiresIPhoneOS 39 | 40 | UIMainStoryboardFile 41 | Main 42 | UIRequiredDeviceCapabilities 43 | 44 | armv7 45 | 46 | UISupportedInterfaceOrientations 47 | 48 | UIInterfaceOrientationPortrait 49 | UIInterfaceOrientationLandscapeLeft 50 | UIInterfaceOrientationLandscapeRight 51 | 52 | 53 | 54 | -------------------------------------------------------------------------------- /WechatPayDemo/WechatPayDemo-Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header 3 | // 4 | // The contents of this file are implicitly included at the beginning of every source file. 5 | // 6 | 7 | #import 8 | 9 | #ifndef __IPHONE_5_0 10 | #warning "This project uses features only available in iOS SDK 5.0 and later." 11 | #endif 12 | 13 | #ifdef __OBJC__ 14 | #import 15 | #import 16 | #endif 17 | -------------------------------------------------------------------------------- /WechatPayDemo/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | -------------------------------------------------------------------------------- /WechatPayDemo/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // WechatPayDemo 4 | // 5 | // Created by Alvin on 3/22/14. 6 | // Copyright (c) 2014 Alvin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "AppDelegate.h" 12 | 13 | int main(int argc, char * argv[]) 14 | { 15 | @autoreleasepool { 16 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /WechatPayDemoTests/WechatPayDemoTests-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | en 7 | CFBundleExecutable 8 | ${EXECUTABLE_NAME} 9 | CFBundleIdentifier 10 | $(PRODUCT_BUNDLE_IDENTIFIER) 11 | CFBundleInfoDictionaryVersion 12 | 6.0 13 | CFBundlePackageType 14 | BNDL 15 | CFBundleShortVersionString 16 | 1.0 17 | CFBundleSignature 18 | ???? 19 | CFBundleVersion 20 | 1 21 | 22 | 23 | -------------------------------------------------------------------------------- /WechatPayDemoTests/WechatPayDemoTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // WechatPayDemoTests.m 3 | // WechatPayDemoTests 4 | // 5 | // Created by Alvin on 3/22/14. 6 | // Copyright (c) 2014 Alvin. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface WechatPayDemoTests : XCTestCase 12 | 13 | @end 14 | 15 | @implementation WechatPayDemoTests 16 | 17 | - (void)setUp 18 | { 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 | { 25 | // Put teardown code here. This method is called after the invocation of each test method in the class. 26 | [super tearDown]; 27 | } 28 | 29 | - (void)testExample 30 | { 31 | XCTFail(@"No implementation for \"%s\"", __PRETTY_FUNCTION__); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /WechatPayDemoTests/en.lproj/InfoPlist.strings: -------------------------------------------------------------------------------- 1 | /* Localized versions of Info.plist keys */ 2 | 3 | --------------------------------------------------------------------------------