Aliyun

 view release on metacpan or  search on metacpan

lib/AuthV2.pm  view on Meta::CPAN

package Aliyun::AuthV2;
use Crypt::Digest::MD5 qw(md5_hex);
use URI::Escape;
use Data::Dumper qw/Dumper/;
use DateTime;
use DateTime::Format::Strptime qw();
use Hash::Merge;
use version;
our $VERSION = 0.2;

#阿里云API签名
sub new {
    my $class = shift;
    $class = (ref $class) || $class || __PACKAGE__;
    my $self = bless {}, $class;
    $self->{'aliyun_url'} = 'http://gw.api.taobao.com/router/rest';
    return $self;
}

#设置环境
#param:是否是沙盒环境
#param:是否启启用https
sub set_evn {
    my ($self, $is_sanbox, $is_https) = @_;
    if ($is_sanbox) {
        $self->{'aliyun_url'} = $is_https              ?
            'https://gw.api.tbsandbox.com/router/rest' :
            'http://gw.api.tbsandbox.com/router/rest';
    }
    else {
        $self->{'aliyun_url'} = $is_https        ?
            'https://eco.taobao.com/router/rest' :
            'http://gw.api.taobao.com/router/rest';
    }
}

#设置app key
sub set_appkey {
    $_[0]->{'app_key'} = $_[1];
}

#设置secret key
sub set_secretkey {
    $_[0]->{'secret_key'} = $_[1];
}

sub set_target_app_key {
    $_[0]->{'set_target_app_key'} = $_[1];
}

sub set_session {
    $_[0]->{'set_session'} = $_[1];
}

sub set_partner_id {
    $_[0]->{'set_partner_id'} = $_[1];
}

sub _get_public_params {
    my $public_params = {
        'app_key'     => $_[0]->{'app_key'},
        'sign_method' => 'md5',
        'timestamp'   =>
        DateTime::Format::Strptime->new(pattern => '%Y-%m-%d %H:%M:%S')->format_datetime(DateTime->now(time_zone =>
            'local')),
        'format'      => 'json',
        'v'           => '2.0',
    };
    foreach ('set_target_app_key', 'set_session', 'set_partner_id') {
        if ($self->{$_}) {
            $public_params->{$_} = $self->{$_};
        }
    }
    return $public_params;
}



( run in 1.445 second using v1.01-cache-2.11-cpan-5837b0d9d2c )