<key>LSApplicationQueriesSchemes</key> <array><string>wechat</string> <string>weixin </string> </array>
[[UMSocialManager defaultManager] setPlaform:UMSocialPlatformType_WechatSession appKey:kWechatID appSecret:kWechatKey redirectURL:@[url=http://mobile.umeng.com/social]http://mobile.umeng.com/social[/url]];
+ (void)createWechatOrderWithGoldType:(NSString *)type amount:(NSNumber *)amount{
// 向后台请求订单,根据自己公司后台给的url来做
[RequestTool requestWithType:POST RRLString:kWechatURL parameter:@{@"user_id":[UserLoginStateManager shareManager].model.userID,@"sign_key":[UserLoginStateManager shareManager].model.sign_key,@"gold_type":type,@"amount":amount} HTTPHeader:nil callBlock:^(NSData *data, NSError *error) {
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil]; NSLog(@"%@",dic);
if (!dic[@"error_msg"]) {
// 调用自己写的微信支付方法
[self WXPayWithAppid:dic[@"appid"] noncestr:dic[@"noncestr"] package:dic[@"package"] partnerid:dic[@"partnerid"] prepayid:dic[@"prepayid"] timestamp:dic[@"timestamp"] key:dic[@"key"] sign:dic[@"sign"]]; } }];
}
#pragma mark 微信支付方法+ (void)WXPayWithAppid:(NSString *)appid noncestr:(NSString *)noncestr package:(NSString *)package partnerid:(NSString *)partnerid prepayid:(NSString *)prepayid timestamp:(NSString *)timestamp key:(NSString *)key sign:(NSString *)sign{
//需要创建这个支付对象
PayReq *req = [[PayReq alloc] init];
//由用户微信号和AppID组成的唯一标识,用于校验微信用户
req.openID = appid;
// 商家id,在注册的时候给的
req.partnerId = partnerid;
// 预支付订单这个是后台跟微信服务器交互后,微信服务器传给你们服务器的,你们服务器再传给你
req.prepayId = prepayid;
// 根据财付通文档填写的数据和签名
req.package = package;
// 随机编码,为了防止重复的,在后台生成
req.nonceStr = noncestr;
// 这个是时间戳,也是在后台生成的,为了验证支付的
NSString * stamp = timestamp;
req.timeStamp = stamp.intValue;
// 这个签名也是后台做的
req.sign = sign;
//发送请求到微信,等待微信返回onResp
[WXApi sendReq:req];
}
// 判断手机有没有微信
if ([WXApi isWXAppInstalled]) {
wechatButton.hidden = NO;
}else{
wechatButton.hidden = YES;
}
// iOS9.0以前调用此方法
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url {
if ([url.host isEqualToString:@"pay"]) {
return [WXApi handleOpenURL:url delegate:self];
}
}
// iOS9.0及9.0以后调用此方法
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation{
// 在此方法中做如下判断,因为还有可能有其他的支付,如支付宝就是@"safepay"
if ([url.host isEqualToString:@"pay"]) {
return [WXApi handleOpenURL:url delegate:self];
}
return YES;
}
- (void)onResp:(BaseResp *)resp{
if ([resp isKindOfClass:[PayResp class]]) {
// 微信支付
PayResp*response=(PayResp*)resp;
switch(response.errCode){
case 0:
NSLog(@“支付成功!");
break;
case -1:
NSLog(@"支付失败!");
break;
case -2:
NSLog(@"支付失败!");
break;
default:
NSLog(@"支付失败!");
break;
}
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有