ios集成支付宝

首先使用支付宝提供的openssl 生成rsa 的公钥 和私钥 。

 NSString *privateKey = @"MIICeAIBADANBgkqhkiG9w0BAQEFAASCAmIwggJeAgEAAoGBAMNhV8wFBELkSKN4vEKLwzlY+M9oTVbmvffig7oz/lh9xTaEhj4iY20q9AI7lAy2NAGvhN/f0mUVugk9dDDi5z1LgMh56QU+kiO/JEVrXeRXgCbew3z2VOUuNOF4kVWSimrCAs+lSjVKDOKCzFIM8y7eNS74aSNcRVRrE3Xl6GUJAgMBAAECgYEAjb+Czg7Zr5olpQwEMZdqlKGbKga3DZQsQLqC7UWpgxQET3BIYK3cSqh+DVyiJbLO+mYX1cBxyUrBBNEkCg+kyUsCPy4r+/Dkplc8fvw51scYK1mNDysB3W7aVdW0ikfze5vxzTbogGGALSvFK4jHaf+kM3PqhYQmEaAvwlW9HK0CQQDyKp+11ARMrB7zeGkW9pxKdc8o99poldZyQZlKhWdjIf4h1VfYUlg6zknZgaVMpLQNg2jToBRtB5BE8EALEXeLAkEAzoqHoeGNW9VzUQr7Lq7dGGEz4VGVUbD95kP8kfEpFyoUCbyp8z2BgeyAKelnNxjl3i4+gtM0gyP/t8FNYCCIOwJBANxiQfp9unP0aC52tFy7jbyNvjuwZEmtov1UCacyBMbI1rf/qfQp7DWIKtkRDVfUxC9QGgQNuMkIixjR89aezMUCQQCADKSwOT1BfSFEUnGN7L2IWuMmQ0U242tWMjpJZOFbyiuoKb6X3j8HhM+krF7gauBAkh0RUM4Sq+PjUcWd3i13AkAt94kMFEOm61jMT/7xwzVoWz3qhm+TchpLCDRc1F8Mv6JvXFWOobN3gBObQK64n1cu+Pmni9fpqp0eGd9qWmN+";

  

如图所示,当用户完成支付之后重新唤醒有用
NSString *appScheme = @"zfb";
名字与plist保持一致

  

    //1.订单模型
    Order * order = [[Order alloc]init];
    //2.签名
    id<DataSigner> signer = CreateRSADataSigner(privateKey);
    //3.传入订单描述 进行 签名
    NSString *orderSpec=order.description;
    NSString *signedString=[signer signString:orderSpec];
    //4.生成订单字符串
    NSString *orderString = [NSString stringWithFormat:@"%@&sign=\"%@\"&sign_type=\"%@\"",orderSpec, signedString, @"RSA"];

  

    //发送请求
    [[AlipaySDK defaultService] payOrder:orderString fromScheme:appScheme callback:^(NSDictionary *resultDic) {
                    NSLog(@"reslut = %@",resultDic);
                }];

  

@property(nonatomic, copy) NSString * partner;
@property(nonatomic, copy) NSString * seller;
@property(nonatomic, copy) NSString * tradeNO;
@property(nonatomic, copy) NSString * productName;
@property(nonatomic, copy) NSString * productDescription;
@property(nonatomic, copy) NSString * amount;
@property(nonatomic, copy) NSString * notifyURL;

@property(nonatomic, copy) NSString * service;
@property(nonatomic, copy) NSString * paymentType;
@property(nonatomic, copy) NSString * inputCharset;
@property(nonatomic, copy) NSString * itBPay;
@property(nonatomic, copy) NSString * showUrl;


@property(nonatomic, copy) NSString * rsaDate;//可选
@property(nonatomic, copy) NSString * appID;//可选

@property(nonatomic, readonly) NSMutableDictionary * extraParams;

  

- (NSString *)description {
	NSMutableString * discription = [NSMutableString string];
    if (self.partner) {
        [discription appendFormat:@"partner=\"%@\"", self.partner];
    }
	
    if (self.seller) {
        [discription appendFormat:@"&seller_id=\"%@\"", self.seller];
    }
	if (self.tradeNO) {
        [discription appendFormat:@"&out_trade_no=\"%@\"", self.tradeNO];
    }
	if (self.productName) {
        [discription appendFormat:@"&subject=\"%@\"", self.productName];
    }
	
	if (self.productDescription) {
        [discription appendFormat:@"&body=\"%@\"", self.productDescription];
    }
	if (self.amount) {
        [discription appendFormat:@"&total_fee=\"%@\"", self.amount];
    }
    if (self.notifyURL) {
        [discription appendFormat:@"&notify_url=\"%@\"", self.notifyURL];
    }
	
    if (self.service) {
        [discription appendFormat:@"&service=\"%@\"",self.service];//mobile.securitypay.pay
    }
    if (self.paymentType) {
        [discription appendFormat:@"&payment_type=\"%@\"",self.paymentType];//1
    }
    
    if (self.inputCharset) {
        [discription appendFormat:@"&_input_charset=\"%@\"",self.inputCharset];//utf-8
    }
    if (self.itBPay) {
        [discription appendFormat:@"&it_b_pay=\"%@\"",self.itBPay];//30m
    }
    if (self.showUrl) {
        [discription appendFormat:@"&show_url=\"%@\"",self.showUrl];//m.alipay.com
    }
    if (self.rsaDate) {
        [discription appendFormat:@"&sign_date=\"%@\"",self.rsaDate];
    }
    if (self.appID) {
        [discription appendFormat:@"&app_id=\"%@\"",self.appID];
    }
	for (NSString * key in [self.extraParams allKeys]) {
		[discription appendFormat:@"&%@=\"%@\"", key, [self.extraParams objectForKey:key]];
	}
	return discription;
}

  

posted @ 2015-09-02 15:23  cshhs  阅读(267)  评论(1编辑  收藏  举报