Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Authorize.net CIM-API用户名无效或不存在的原因_Php_Codeigniter_Authorize.net_Authorize.net Cim - Fatal编程技术网

Php Authorize.net CIM-API用户名无效或不存在的原因

Php Authorize.net CIM-API用户名无效或不存在的原因,php,codeigniter,authorize.net,authorize.net-cim,Php,Codeigniter,Authorize.net,Authorize.net Cim,我已经使用authorize.net CIM创建了一个应用程序。在测试模式下使用应用程序时,一切正常。当我从测试模式切换到实时模式并粘贴正确的用户id和事务密钥时,会显示:API用户名无效或不存在 这毫无意义。我100%确信api用户名和事务密钥是正确的 我正在使用CIM codeigniter库。下面是处理CIM的设置和初始化的代码 <?php if (!defined('BASEPATH')) exit('No direct script access allowed'); /* By

我已经使用authorize.net CIM创建了一个应用程序。在测试模式下使用应用程序时,一切正常。当我从测试模式切换到实时模式并粘贴正确的用户id和事务密钥时,会显示:API用户名无效或不存在

这毫无意义。我100%确信api用户名和事务密钥是正确的

我正在使用CIM codeigniter库。下面是处理CIM的设置和初始化的代码

<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
/*
By: Spicer Matthews <spicer@cloudmanic.com>
Company: Cloudmanic Labs, LLC
Website: http://www.cloudmanic.com

Based On Work From: 
- John Conde <johnny@johnconde.net>
- http://www.communitymx.com/content/article.cfm?page=4&cid=FDB14
*/

class AuthorizeCimLib
{
    private $_CI; 
    private $_loginname;
    private $_loginkey;
    private $_response;
    private $_resultCode;
    private $_responseCode;
    private $_responseText;
    private $_success;
    private $_error;
    private $_url;
    private $_parsedresponse;
    private $_xml;
    private $_call;
    private $_responsecall;
    private $_directresponse;
    private $_items = array();
    private $_params = array();
    private $_validationmode = 'liveMode';
    private $_errormsg = '';
    private $_loginhost = 'api.authorize.net';
    private $_testhost = 'apitest.authorize.net';
    private $_loginpath = '/xml/v1/request.api';

    //
    // Construct..... 
    //
    function __construct()
    {
        $this->_CI =& get_instance();
        $this->_set_url();
        $this->_set_default_params();

        // If the config is setup properly use that to initialize
        $this->_CI->config->load('authorizenet');

        if($this->_CI->config->item('authorizenetname') && 
                $this->_CI->config->item('authorizenetkey') &&
                $this->_CI->config->item('authorizenettestmode'))
        {
            $this->initialize($this->_CI->config->item('authorizenetname'), $this->_CI->config->item('authorizenetkey'), $this->_CI->config->item('authorizenettestmode'));
        }

        log_message('debug', "AuthorizeCimLib Class Initialized");
    }

    //
    // Call this function to setup the library variables. Such as API keys.
    //
    public function initialize($name, $key, $testmode = FALSE)
    {
        // Are we in test mode??
        if($testmode)
        {
            $this->_set_testmode();
        }

        // Setup login names and keys.
        $this->_loginname = $name;
        $this->_loginkey = $key;
    }

    //
    // Set validation mode.
    //
    public function set_validationmode($mode)
    {
        $types = array('none', 'testMode', 'liveMode', 'oldLiveMode');

        if(in_array($mode, $types))
        {
            $this->_validationmode = $mode;
            return 1;
        } 
        else
        {
            log_message('debug', "AuthorizeCimLib Not A Valid Test Mode");
            return 0;
        }
    }

    //
    // Get validation mode.
    //
    public function get_validationmode()
    {
        return $this->_validationmode;
    }

    //
    // Set Parameters to send to Authorize.net
    //
    public function set_data($field, $value)
    {
        $this->_params[$field] = $value;
    }

    //
    // C;ear Parameters data
    //
    public function clear_data()
    {
        $this->_params = array();
        $this->_set_default_params();
    }

经过几个小时的拔头发,我终于明白了这一点

库类的
\u构造
中的if语句逻辑有一些错误。当它检查配置选项时,如果您的测试模式设置为
FALSE
,那么它将不会初始化。。。因为您正在向if语句传递一个
FALSE
值(这发生在我的文件的第49行附近)。要解决这个问题,只需从if语句中删除“testmode”检查

这就是它的样子:

if($this->_CI->config->item('authorizenetname') && $this->_CI->config->item('authorizenetkey'))
{
    $this->initialize($this->_CI->config->item('authorizenetname'), $this->_CI->config->item('authorizenetkey'), $this->_CI->config->item('authorizenettestmode'));
}

我知道这个答案有些晚了,但希望能有所帮助。

你有没有想过这个问题?我正在处理完全相同的问题。