1. 去微信開放平臺注冊app key ,獲取相應(yīng)的app key 創(chuàng)建應(yīng)用
2. 在工程中導(dǎo)入weixinsdk
3. 添加相關(guān)依賴庫
CoreTelephony.framework
SystemConfiguration.framework
libz.tbd
libsqlite3.0.tbd
libc++.tbd
4.配置文件的添加
Info.plist:
????添加URL types
? ? ? ? ? ? Item 0:
? ? ? ? ? ? Document Role ?Editor
? ? ? ? ? ? URL identifier ? ?weichat
? ? ? ? ? ? URL Schemes?
? ? ? ? ? ? ? ? ? ? Itime 0. ? XXXXXXXX(開放平臺申請的到的key值)
5.去工程中的Info中修改URL Types如圖,將申請的到的key值填在相應(yīng)的位置
6. 進入AppDelegate.m的application:?didFinishLaunchingWithOptions: ?方法進行微信支付的初始化設(shè)置
(1).????首先要導(dǎo)入<WXApiDelegate>,
(2).????在代碼中注冊微信支付:[WXApi registerApp:(申請的id)]
(3).????WXApi.h中是微信支付api所暴露的使用方法:
? - (void)registerApp:(NSString *)appid; ? //將申請的appkey注冊到微信中去
?? ?+ (BOOL)isWXAppInstalled; ? ? ? ? ? ? ? ? ? //檢測是否安裝微信客戶端
? ? + (BOOL)sendReq:(BaseReq *)req; ? ? ?//發(fā)送請求到微信等待微信返回onResp
?? ?+ (BOOL)sendAuthReq:(SendAuthReq *)req viewController:(UIViewController *)viewController delegate:(id )delegate; ? // 發(fā)送授權(quán)到微信预茄,等待微信返回onResp
? ? 支付時方法調(diào)用:
????PayReq:第三方向微信終端發(fā)起支付的消息體結(jié)構(gòu),將自己的訂單信息賦值給PayReq對應(yīng)的屬性再進行支付
? ? partnerId: 商家向財付通申請的商家id
? ? prepayId: ?預(yù)支付訂單
? ? nonceStr: 隨機串晚顷,防重發(fā)
? ? timeStamp:時間戳
? ? package: ?商家根據(jù)財付通文檔天蝎的數(shù)據(jù)和簽名
? ? sign: ? ? ? ? 商家根據(jù)微信開放平臺文檔對數(shù)據(jù)做的簽名
7.支付回調(diào)
????支付回調(diào)SenAuthResp:微信處理完認(rèn)證和權(quán)限之后返回的結(jié)果
- (void)onResp:(BaseResp *)resp
{
? ? //向微信請求授權(quán)后得到的響應(yīng)
????if([rep isKindOfClass:[SenAuthResp class]] && rep.errCode == 0)
????{
? ? ?//微信支付 url: ?wx_base_url = @"https://api.weixin.qq.com/sns"
? ? SenAuthResp *temp = (SenAuthResp *)rep;
? ? AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
? ? manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json",@"text/html",@"text/json",@"text/javascript",@"text/plain",@"image/jpeg",@"application/x-png",nil];
? ? NSString *accessUrlStr = [NSString stringWithFormat:@"%@/oauth2/accsee_token?appid=%@%secret=%@&code=%@&grant_type=authorization_code",wx_base_url,申請的id, key,temp,code];
????}
}