文章来自:http://blog.csdn.net/intbird
免费的信用卡扫描SDK:https://www.card.io/
Android Demo
0.上图:
1,gradle 配置
dependencies {
compile fileTree(dir: ‘libs’, include: [‘*.jar’])
compile ‘com.android.support:appcompat-v7:23.0.0’
compile ‘io.card:android-sdk:5.0.1’
}
2,清单
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.intbird.soft.intbirdcardscan">
<!-- Permission to vibrate - recommended, allows vibration feedback on scan -->
<uses-permission android:name="android.permission.VIBRATE" />
<!-- Permission to use camera - required -->
<uses-permission android:name="android.permission.CAMERA" />
<uses-feature
android:name="android.hardware.camera"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.autofocus"
android:required="false" />
<uses-feature
android:name="android.hardware.camera.flash"
android:required="false" />
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<!-- Activities responsible for gathering payment info -->
<activity
android:name="io.card.payment.CardIOActivity"
android:configChanges="keyboardHidden|orientation" />
<activity android:name="io.card.payment.DataEntryActivity" />
</application>
</manifest>
3,代码
package com.intbird.soft.intbirdcardscan;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;
import io.card.payment.CardIOActivity;
import io.card.payment.CreditCard;
public class MainActivity extends AppCompatActivity {
private final int MY_SCAN_REQUEST_CODE = 1000;
private String scanResultStr = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.btn_send).setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View view) {
Intent scanIntent = new Intent(MainActivity.this, CardIOActivity.class);
// customize these values to suit your needs.
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_EXPIRY, true); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_CVV, false); // default: false
scanIntent.putExtra(CardIOActivity.EXTRA_REQUIRE_POSTAL_CODE, false); // default: false
// MY_SCAN_REQUEST_CODE is arbitrary and is only used within this activity.
startActivityForResult(scanIntent, MY_SCAN_REQUEST_CODE);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if(requestCode == MY_SCAN_REQUEST_CODE){
if(data != null && data.hasExtra(CardIOActivity.EXTRA_SCAN_RESULT)){
CreditCard scanResult = data.getParcelableExtra(CardIOActivity.EXTRA_SCAN_RESULT);
String cardNo = scanResult.cardNumber ;
scanResultStr += cardNo +"\n";
if(scanResult.isExpiryValid()) {
String extra = scanResult.expiryMonth + "\t" + scanResult.expiryYear + "\t";
scanResultStr += extra +"\n";
}
if (scanResult.cvv != null) {
// Never log or display a CVV
String cvv = scanResult.cvv;
scanResultStr += cvv +"\n";
}
if (scanResult.postalCode != null) {
String postCode = scanResult.postalCode;
scanResultStr += postCode +"\n";
}
}else{
scanResultStr = "scan cacel";
}
showScanResult(scanResultStr);
}
}
private void showScanResult(String result){
TextView textView = (TextView)findViewById(R.id.tv_cardinfo);
textView.setText(result);
}
}
IOS Demo
0,上图
1,podfile
pod ‘CardIO’
2,代码
@implementation ViewController
CardIOPaymentViewController *scanViewController;
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[CardIOUtilities preload];
}
- (IBAction)btnSend:(id)sender {
scanViewController = [[CardIOPaymentViewController alloc] initWithPaymentDelegate:self];
[self presentViewController:scanViewController animated:YES completion:nil];
}
-(void)userDidCancelPaymentViewController:(CardIOPaymentViewController *)paymentViewController{
_lbCardInfo.text = @"caceled";
[scanViewController dismissViewControllerAnimated:YES completion:nil];
}
-(void)userDidProvideCreditCardInfo:(CardIOCreditCardInfo *)cardInfo inPaymentViewController:(CardIOPaymentViewController *)paymentViewController{
_lbCardInfo.text = [NSString stringWithFormat:@"No:%@, expiry:%lu/%lu" ,
cardInfo.cardNumber,cardInfo.expiryMonth,cardInfo.expiryYear];
[scanViewController dismissViewControllerAnimated:YES completion:nil];
}
@end
文章来自::http://blog.csdn.net/intbird
android demo:https://github.com/intbird/ANDIntbirdCardScan
IOS demo:https://github.com/intbird/IOSIntbirdCardScan