use Net::SMTP;
use LWP::UserAgent;
use HTTP::Cookies;
use HTTP::Headers;
use HTTP::Response;
use Encode;
use Switch;
use File::Temp qw/tempfile/;
use HTTP::Date qw(time2iso str2time time2iso time2isoz);
my $CurrTime = time2iso( time() );
my $dis_mainpublish = '中均资本';
my $ua = LWP::UserAgent->new( ssl_opts => {verify_hostname => 0});
$ua->timeout(10);
$ua->env_proxy;
my $now = time();
$ua->agent('Mozilla/5.0');
my $cookie_jar = HTTP::Cookies->new(
file => 'lwp_cookies.txt',
autosave => 1,
ignore_discard => 1
);
$ua->cookie_jar($cookie_jar);
my $str = ( rand(1) );
##获取验证码https://www.zjtest4.com/validcode/generate-validcode.do
my $response =
$ua->get("https://www.zjtest4.com/validcode/generate-validcode.do?$str");
print "$str is $str
";
if ( $response->is_success ) {
$r = $response->decoded_content;
# print $response->decoded_content; # or whatever
}
else {
die $response->status_line;
}
my ( $fh, $filename ) =
tempfile( "wj_qrcode_XXXX", SUFFIX => ".jpg", DIR => 'c:\' );
binmode $fh;
print $fh $r;
close $fh;
print encode( "gbk", decode( "utf8","登录二维码已经下载到本地")) ."[ $filename ]
";
##打开图片
system("start $filename ");
my $validCode = <STDIN>;
chomp $validCode;
print "$validCode is $validCode
";
#my $url="https://www.zjtest4.com/business/dispatch_post.do";
my $login_url = 'https://www.zjtest4.com/business/dispatch_post.do?action=submitAdminLogin';
my $res = $ua->post(
$login_url,
{
'userName' => 'w123456',
'userPass1' => 'w123456',
'userPass' => '3d24b838770ee90773804e8599e549ff',
'validCode' => "$validCode"
}
);
my $head = $res->header('Location');
#print $res->header('Location');
print $res->status_line . "
";
#print $res->as_string()
; #获取的是原始内容,包括响应头,响应正文
my $content = $res->content();
my $response = $ua->get("$head");
if ( $response->is_success ) {
#print $response->content;
$r = $response->content;
my $str = encode( "gbk", decode( "utf8", "$r" ) );
print "login_info is $str
";
}
else {
$r = $response->content;
print $response->content;
}
###调用发布产品接口
my $url="https://www.zjtest4.com/web/adminauth/post";
my $res = $ua->post(
$url,
{
'accessType' => '1',
'addUnit' => '1000',
'assignType' => '1',
'bonus' => "0",
'bonusName' => "请选择红包类型",
'borrowerInfo' => "scan",
'buyAcctTypes' => "1",
'buyFromTime' => "2016-07-27 12:01",
'buyToTime' => "2016-07-28 23:59:59",
'capitalPurpose' => "",
'compound' => "2",
'contractSn' => "340",
'custody' => "scan",
'daysOfYear' => "360",
'delegator' => "3",
'duration' => "3",
'entryUnit' => "1000",
'expirationDate' => "2015-1-31",
'financeType' => "1",
'initSoldQuota' => "1000",
'entryUnit' => "0",
'isOnlyForFirst' => "1",
'manualSn' => "0",
'maxClient' => "0",
'maxUnit' => "10000",
'maxYield' => "0.03",
'method' => "/admin/product/publish",
'name' => "温金宝-987654321",
'entryUnit' => "1000",
'entryUnit' => "1000",
'entryUnit' => "1000",
'entryUnit' => "1000",
'entryUnit' => "1000",
'entryUnit' => "1000",
'entryUnit' => "1000",
'entryUnit' => "1000",
'entryUnit' => "1000",
'naturalSeasonRepaymentDay'=>'1',
'precision'=>'2',
'productId'=>'99999999',
'productIntro'=>'scan',
'productPublishType'=>'2',
'productType'=>'4',
'publishChannel'=>'3001',
'quotaForFirst'=>'100000',
'recommendDate'=>'2016-07-27',
'repaySource'=>'scan',
'riskInfo'=>'scan',
'riskLevel'=>'1',
'safeguard'=>'1',
'settlementDate'=>'2016-08-01',
'stageNum'=>'1',
'stagingTemplateId'=>'',
'stairYieldSn'=>'',
'stockAwardYield'=>'0',
'supportCouponType'=>'2',
'supportStock'=>'2',
'supportTransfer'=>'2',
'totalQuota'=>'100000000',
'unitValue'=>'1',
'valueEndDate'=>'2016-07-31',
'valueStartDate'=>'2016-07-29',
'wzeCardYield'=>'0',
'wzeCardYieldOnOff'=>'2',
'yield'=>'0.02',
'yieldForFirst'=>'0.01'
},
'User-Agent'=>'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:45.0) Gecko/20100101 Firefox/45.0'
);
print $res->header('Location');
print $res->status_line."
";
my $str= $res->as_string();#获取的是原始内容,包括响应头,响应正文