Javascript 2检查未经授权的错误Laravel
我试图使用Sandbox2Checkout API,但我面临一些问题。 我使用Laravel作为php框架,使用2co.min.js生成令牌。 当我填写输入并按submit时,我得到了“未授权” 我从我的沙箱帐户和公钥、私钥中获取卖家id 对于API并检查了它们,但我仍然得到以下错误: 卖方id、公钥和私钥 HTML代码Javascript 2检查未经授权的错误Laravel,javascript,php,jquery,laravel,2checkout,Javascript,Php,Jquery,Laravel,2checkout,我试图使用Sandbox2Checkout API,但我面临一些问题。 我使用Laravel作为php框架,使用2co.min.js生成令牌。 当我填写输入并按submit时,我得到了“未授权” 我从我的沙箱帐户和公钥、私钥中获取卖家id 对于API并检查了它们,但我仍然得到以下错误: 卖方id、公钥和私钥 HTML代码 @csrf 卡号 有效期(年月日) / CVC JS代码 <script src="//ajax.googleapis.com/ajax/libs/jquery
@csrf
卡号
有效期(年月日)
/
CVC
JS代码
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
<script src="https://www.2checkout.com/checkout/api/2co.min.js"></script>
<script>
// Pull in the public encryption key for our environment
// Called when token created successfully.
var successCallback = function (data) {
var myTokenInput = document.getElementById('token1');
// Set the token as the value for the token input
myTokenInput.value = data.response.token.token;
// IMPORTANT: Here we call `submit()` on the form element directly instead of using jQuery to prevent and infinite token request loop.
myForm.submit();
};
// Called when token creation fails.
var errorCallback = function (data) {
if (data.errorCode === 200) {
console.log(data);
} else {
console.log(data);
}
};
var tokenRequest = function () {
// Setup token request arguments
var args = {
sellerId: "203840804",
publishableKey: "ACC02BE7-70FC-4AEF-9F75-D592E299DEDA",
ccNo: $("#ccNo").val(),
cvv: $("#cvv").val(),
expMonth: $("#expMonth").val(),
expYear: $("#expYear").val(),
billingAddr: $("#billingAddr").val()
};
// Make the token request
TCO.requestToken(successCallback, errorCallback, args);
};
$(function () {
// Pull in the public encryption key for our environment
TCO.loadPubKey('production');
$("#myCCForm").submit(function (e) {
e.preventDefault();
// Call our token request function
tokenRequest();
// Prevent form from submitting
return false;
});
});
//为我们的环境拉入公共加密密钥
//成功创建令牌时调用。
var successCallback=函数(数据){
var myTokenInput=document.getElementById('token1');
//将令牌设置为令牌输入的值
myTokenInput.value=data.response.token.token;
//重要提示:这里我们直接在表单元素上调用'submit()',而不是使用jQuery来防止和无限令牌请求循环。
myForm.submit();
};
//当令牌创建失败时调用。
var errorCallback=函数(数据){
如果(data.errorCode==200){
控制台日志(数据);
}否则{
控制台日志(数据);
}
};
var tokenRequest=函数(){
//设置令牌请求参数
变量args={
sellerId:“203840804”,
可发布密钥:“ACC02BE7-70FC-4AEF-9F75-D592E299DEDA",
ccNo:$(“#ccNo”).val(),
cvv:$(“#cvv”).val(),
expMonth:$(“#expMonth”).val(),
expYear:$(“#expYear”).val(),
BillingAddress:$(“#BillingAddress”).val()
};
//发出令牌请求
requestToken(successCallback、errorCallback、args);
};
$(函数(){
//为我们的环境拉入公共加密密钥
TCO.loadPubKey(“生产”);
$(“#myCCForm”)。提交(功能(e){
e、 预防默认值();
//调用我们的令牌请求函数
令牌请求();
//阻止表单提交
返回false;
});
});
我需要帮助伙计们您需要更改脚本中的senderId和publishableKey 将tokenRequest函数更改为以下函数:
var tokenRequest = function () {
// Setup token request arguments
var args = {
sellerId: "901389630",
publishableKey: "A4B8A470-61A2-470E-9DCB-013A033FD206",
ccNo: $("#ccNo").val(),
cvv: $("#cvv").val(),
expMonth: $("#expMonth").val(),
expYear: $("#expYear").val(),
billingAddr: $("#billingAddr").val()
};
// Make the token request
TCO.requestToken(successCallback, errorCallback, args);
};
就像@LahiruTM写的那样,将TCO.loadPubKey('production');
更改为TCO.loadPubKey('sandbox');
尝试用TCO.loadPubKey('sandbox')替换TCO.loadPubKey('production');
var tokenRequest = function () {
// Setup token request arguments
var args = {
sellerId: "901389630",
publishableKey: "A4B8A470-61A2-470E-9DCB-013A033FD206",
ccNo: $("#ccNo").val(),
cvv: $("#cvv").val(),
expMonth: $("#expMonth").val(),
expYear: $("#expYear").val(),
billingAddr: $("#billingAddr").val()
};
// Make the token request
TCO.requestToken(successCallback, errorCallback, args);
};