perl 自动发产品
2016-07-27 12:41
316 查看
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\n"; 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 ] \n"; ##打开图片 system("start $filename "); my $validCode = <STDIN>; chomp $validCode; print "\$validCode is $validCode\n"; #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 . "\n"; #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\n"; } 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."\n"; my $str= $res->as_string();#获取的是原始内容,包括响应头,响应正文
相关文章推荐
- java使double保留两位小数的多方法 java保留两位小数
- 救济金发放 (The Dole QUEUE UVa 133)
- 矩阵基础1007 UVA 11149
- Spring MVC异常处理
- Google protocol buffer的配置和使用(Linux&&Windows)
- C#工作笔记
- Java设计模式透析之 —— 单例(Singleton)
- 射频全网通笔记(附全球频段划分及主要运营商对应表)
- 矩阵基础1006 HDU 4549
- 从头学android_alertDialog的使用
- CSU 1723: 想打架吗?算我一个!所有人,都过来!
- 射频全网通笔记(附全球频段划分及主要运营商对应表)
- 从零开始的Android新项目9 - 前端用后台接口设计
- mysql 优化
- 助词复习—1
- CRM----管理软件分析( ERP/CRM/OA)
- hdu2196 Computer 【树形dp】
- Spring(二) 依赖注入
- 顺序表应用6:有序顺序表查询
- 腾讯课堂学习资源链接地址