我有一个使用Perl和Tk的应用程序,我们使用的Perl版本是v5.30.3。我已经编写了一个程序,用于与发送JSON数据的REST API通信。
这是程序
use REST::Client;
use JSON;
use Data::Dumper;
@reference = undef; @authCode = undef; @line = undef; $num = 0;
$merchantId = 1000005;
@posData = undef;
$posData[1] = 'Manual'; #panCaptureMethod
$posData[2] = 'false'; #cardPresent
$posData[3] = 'Attended'; #deviceAttendance
$posData[4] = 'KeyedOnly'; #deviceInputCapability
$posData[5] = 'OnPremise'; #deviceLocation
$posData[6] = 'Supported'; #partialApprovalSupport
$posData[7] = 'Unknown'; #pinCaptureCapability
$index = (index($exp, "/"));
$month = substr($exp,0,$index);
$year = substr($exp,$index+1);
my $client = REST::Client->new();
$client->setHost("https://sandbox.api.mxmerchant.com/checkout/v3/");
$client->addHeader('Accept', 'application/json');
$client->addHeader('Content-Type', 'application/json');
$client->addHeader('Authorization', 'Basic TkxvTXhDdlNzaWpSNFJkOHFPWEx5QV=');
$amt = sprintf('%.2f',$amt);
%rec_hash = (
merchantId => $merchantId,
tenderType => "Card",
amount => $amt,
paymentType => "Sale",
cardAccount => {
number => $card,
expiryMonth => $month,
expiryYear => $year,
cvv => $cvv,
avsStreet => $GA_A[6],
avsZip => $zip
},
customer => {
name => $name,
firstName => $fname,
lastName => $lname
},
posData => {
cardholderPresence => $cardholderPresence,
panCaptureMethod => $posData[1],
cardPresent => $posData[2],
deviceAttendance => $posData[3],
deviceInputCapability => $posData[4],
deviceLocation => $posData[5],
partialApprovalSupport => $posData[6],
pinCaptureCapability => $posData[7]
}
);
my $json = encode_json \%rec_hash;
$client->POST('payment?echo=true', $json);
$response = $client->responseContent();
$json_data = decode_json($response);
$error = 'NO';
$status = $json_data->{status};
$authMessage = $json_data->{authMessage};
$errorCode = $json_data->{errorCode};
$errorMessage = $json_data->{message};
$message = $authMessage;
if ($errorCode ne '')
{
$error = 'YES';
$status = $errorCode;
$message = $errorMessage;
}
$reference = $json_data->{reference};
$authCode = $json_data->{authCode};
return($status, $message, $error);
当我使用perl.exe运行这个程序时,在环境变量中包含了所有必要的路径语句,它工作了。它发送了请求,我得到了正确的响应。
我遇到的问题是,当我在测试环境中使用我们编译的.exe时,它不工作。
无法通过位于PERL2EXE_STORAGE/LWP/Protocol/ www.example.com第157行“URI::foreign”包找到对象方法“host”http.pm
为了创建编译后的exe,我使用靛蓝星星Perl 2 exe
我试过添加软件包,更新软件包。
1条答案
按热度按时间vmjh9lq91#
我怀疑您需要在编译的
.exe
中捆绑LWP::Protocol::https
。URL被解析为LWP::Protocol::foreign。LWP::Protocol::https可能很棘手,因为其依赖关系最终需要外部SSL库。