Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/13.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
我的post请求是什么时候基于Woocomece事件触发的,我如何控制我的php代码以便进行调试_Php_Wordpress_Woocommerce_Webhooks - Fatal编程技术网

我的post请求是什么时候基于Woocomece事件触发的,我如何控制我的php代码以便进行调试

我的post请求是什么时候基于Woocomece事件触发的,我如何控制我的php代码以便进行调试,php,wordpress,woocommerce,webhooks,Php,Wordpress,Woocommerce,Webhooks,我在将代码传递给我之前发布了此代码,但这次我有一个不同的问题。我们正在与一家名为GiveX的公司进行集成,该公司只给了我很少的文档。雇佣我的公司必须签署保密协议,所以我认为我不能透露他们透露给我们的很多文件。我会尽可能清楚地表明我的目标。我将把我所有的代码放在我的问题下面,标题是Wordpress中的文件命名 我如何在控制台中记录integrate.php文件中的gi\u check\u balance()函数的$result?我想知道的是giveX返回给我们的是什么。现在,即使这个函数正在向g

我在将代码传递给我之前发布了此代码,但这次我有一个不同的问题。我们正在与一家名为GiveX的公司进行集成,该公司只给了我很少的文档。雇佣我的公司必须签署保密协议,所以我认为我不能透露他们透露给我们的很多文件。我会尽可能清楚地表明我的目标。我将把我所有的代码放在我的问题下面,标题是Wordpress中的文件命名

  • 我如何在控制台中记录
    integrate.php
    文件中的
    gi\u check\u balance()
    函数的
    $result
    我想知道的是giveX返回给我们的是什么。现在,即使这个函数正在向giveX发送一个
    post
    请求,我也不知道我应该在哪里看到这个安慰?在订单完成页面上?或者在某个地方的一些日志中?
  • 添加了什么动作('wp\u ajax\u gi\u check\u balance','gi\u check\u balance')此行是否执行?我在Wordpress文档中看到,add_action是一个在某个点触发的钩子,第一个值应该是一个
    字符串,第二个值应该是一个函数,我看到这是真的,但是创建这个钩子的目的是什么,我看不到字符串在其他地方引用的第一个值,所以它是如何触发的?或者该函数什么时候运行,或者只给它一个
    字符串
    名称和一个函数是否允许该函数运行
  • 还有两个函数
    gi\u check\u balance()
    gi\u secure\u register()
    我如何知道这些函数何时被触发?这些函数如何连接到
    check balance.js
    文件和
    secure register.js
    文件(现在我对
    gi\u secure\u register()的理解)
    功能是,它仅用于测试目的,我知道的唯一区别是post请求中发送的代码标记为
    方法
    一个是
    904
    ,另一个是
    994
    ,它们应该做不同的事情,但通过阅读giveX文档,我无法真正分辨区别
  • 现在我意识到还有一个webhook,它似乎是基于woocommerce中定义在
    integrate.php
    文件中的自定义主题运行的。这个web hook似乎也会向giveX url发出post请求,现在我一辈子都不明白为什么我们会在
    integrate中发出3次post请求。php
    插件文件本身,一个在
    webhook.php
    文件中,另一个在
    js
    文件中。我知道有人很难为我确定这一点,但如果我能知道这些post请求将被触发的顺序是什么情况?这将帮助我理解为什么会出现这种情况三个不同的
  • webhook
    卡号:'.$response->result[3]。
    PIN:'.$response\u reference[1]。
    卡号:'.$response->result[4]。
    参考号:'.$response\u reference[0]“

    当前在电子邮件中返回空变量。我想知道为什么giveX不发回数据?我希望能够将此结果记录在某个我可以看到giveX返回的任何错误的地方
  • 因此,基本上,我希望在基于woocommerce/wordpress中的事件触发某些功能时得到一些帮助。我还想知道实际触发了哪些
    post
    请求,因为我认为我们只需向giveX发送一个请求即可订购这些礼品卡
  • 好的,下面是代码(非常感谢您的光临:)

    plugins/givex/integrate.php

     // Get grouped product ID from child product ID
     function get_parent_grouped_id( $children_id ){
         global $wpdb;
         $results = $wpdb->get_col("SELECT post_id FROM {$wpdb->prefix}postmeta
             WHERE meta_key = '_children' AND meta_value LIKE '%$children_id%'");
         // Will only return one product Id or false if there is zero or many
         return sizeof($results) == 1 ? reset($results) : false;
     }
     /**
      * add_new_topic_hooks will add a new webhook topic hook. 
      * @param array $topic_hooks Esxisting topic hooks.
      */
     function add_new_topic_hooks( $topic_hooks ) {
        // Array that has the topic as resource.event with arrays of actions that call that topic.
        $new_hooks = array(
            'order.gift_card' => array(
                'order_gift_card_filter',
                ),
            );
        return array_merge( $topic_hooks, $new_hooks );
     }
     add_filter( 'woocommerce_webhook_topic_hooks', 'add_new_topic_hooks' );
     /**
      * add_new_topic_events will add new events for topic resources.
      * @param array $topic_events Existing valid events for resources.
      */
     function add_new_topic_events( $topic_events ) {
        // New events to be used for resources.
        $new_events = array(
            'gift_card',
            );
        return array_merge( $topic_events, $new_events );
     }
     add_filter( 'woocommerce_valid_webhook_events', 'add_new_topic_events' );
     /**
      * add_new_webhook_topics adds the new webhook to the dropdown list on the Webhook page.
      * @param array $topics Array of topics with the i18n proper name.
      */
     function add_new_webhook_topics( $topics ) {
        // New topic array to add to the list, must match hooks being created.
        $new_topics = array( 
            'order.gift_card' => __( 'Order Gift Card', 'woocommerce' ),
            );
        return array_merge( $topics, $new_topics );
     }
     add_filter( 'woocommerce_webhook_topics', 'add_new_webhook_topics' );
     /**
      * my_order_item_check will check an order when it is created through the checkout form,
      * if it has product ID 1030 as one of the items, it will fire off the action `order_gift_card_filter`
      * 
      * @param  int    $order_id    The ID of the order that was just created.
      * @param  array  $posted_data Array of all of the data that was posted through checkout form.
      * @param  object $order       The order object.
      * @return null
      */
      function my_order_item_check( $order_id, $posted_data, $order ) {
        $order = wc_get_order( $order_id );
        $order_status = $order->status;
        $items = $order->get_items();
        foreach ( $items as $item ) {
    
            if ( is_a( $item, 'WC_Order_Item_Product' ) ) {
    
                if ( 1457 === $item->get_product_id() ) {
    
              $item_data = $item->get_data();
              $item_meta_data_group = $item_data['meta_data'];
              $gift_card_data = array();
              foreach ( $item_meta_data_group as $item_meta_data ) {
                $gift_card_data[$item_meta_data->key] = $item_meta_data->value;
              }
    
              do_action( 'order_gift_card_filter', $order_id, $posted_data, $order );
    
                }
            }
        }
      }
    
    //The two below actions are what the order.created webhook is tied into, it is up to you to use these if you wish. 
    
    //add_action( 'woocommerce_payment_complete', 'my_order_item_check', 10, 4 );
    add_action( 'woocommerce_checkout_order_processed', 'my_order_item_check', 10, 3 );
    //add_action( 'woocommerce_process_shop_order_meta', 'my_order_item_check', 10, 2 );
    
    add_action( 'wp_enqueue_scripts', 'add_ajax_script' );
    function add_ajax_script() {
      wp_enqueue_script( 'check-balance', plugins_url( '/check-balance.js', __FILE__ ), array('jquery'), '1.0', true );
      wp_enqueue_script( 'secure-register', plugins_url( '/secure-register.js', __FILE__ ), array('jquery'), '1.0', true );
      wp_localize_script( 'check-balance', 'gi_check_balance', array( 'ajax_url' => admin_url('admin-ajax.php') ) );
      wp_localize_script( 'secure-register', 'gi_secure_register', array( 'ajax_url' => admin_url('admin-ajax.php') ) );
    }
    
    add_action( 'wp_ajax_nopriv_gi_check_balance', 'gi_check_balance' );
    add_action( 'wp_ajax_gi_check_balance', 'gi_check_balance' );
    function gi_check_balance() {
      $gx_url_1 = 'https://givexurl-1.com';
      $gx_url_2 = 'https://givexurl-2.com';
      $gx_port_1 = port;
      $gx_port_2 = port;
      $gx_post_url_1 = $gx_url_1 . ':' . $gx_port_1;
      $gx_post_url_2 = $gx_url_2 . ':' . $gx_port_2;
      $gx_user = 'user';
      $gx_password = 'pass';
    
      $gx_card_number = $_POST['gx_card_number'];
    
      $data = array(
        'method' => '994',
        'params' => [
          'en',
          'rc1',
          //null,
          $gx_user,
          $gx_password,
          $gx_card_number,
          $gx_card_pin,
          null
        ],
        'id' => 'test'
      );
    
      $options = array(
        'http' => array(
          'method' => 'POST',
          'header' => 'Content-Type: application/json',
          'content' => json_encode( $data )
        )
      );
    
      $context  = stream_context_create( $options );
      $result = file_get_contents( $gx_post_url_1, false, $context );
      if ( $result == false ) {
        $result = file_get_contents( $gx_post_url_2, false, $context );
      }
      $response = json_decode( $result );
    
      echo $result;
      //echo json_encode($result) ;
      //var_dump( $response );
      //echo $response;
    
      die();
    }
    
    // function only for dev testing purposes
    //add_action( 'wp_ajax_gi_secure_register', 'gi_secure_register' );
    function gi_secure_register() {
      $gx_url_1 = 'https://givexurl-1.com';
      $gx_url_2 = 'https://givexurl-2.com';
      $gx_port_1 = port;
      $gx_port_2 = port;
      $gx_post_url_1 = $gx_url_1 . ':' . $gx_port_1;
      $gx_post_url_2 = $gx_url_2 . ':' . $gx_port_2;
      $gx_user = 'user';
      $gx_password = 'pass';
    
      $gx_register_amount = $_POST['gx_register_amount'];
    
      $data = array(
        'method' => '904',
        'params' => [
          'en',
          'rc2',
          //null,
          $gx_user,
          $gx_password,
          $gx_register_amount,
          null,
          null,
          null
        ],
        'id' => 'test'
      );
    
      $options = array(
        'http' => array(
          'method' => 'POST',
          'header' => 'Content-Type: application/json',
          'content' => json_encode( $data )
        )
      );
    
      $context  = stream_context_create( $options );
      $result = file_get_contents( $gx_post_url_1, false, $context );
      if ( $result == false ) {
        $result = file_get_contents( $gx_post_url_2, false, $context );
      }
      $response = json_decode( $result );
    
      echo json_encode($result);
    
      die();
    }
    
    <?php 
    // required headers
    header("Access-Control-Allow-Origin: *");
    header("Content-Type: application/json; charset=UTF-8");
    
    $passed = false;
    $request_body = file_get_contents('php://input');
    $secret = 'P&_(e>P _I?%/aOW?wv0H.U149+Eyv8bh~qXd<6XrIY8+K0oo]';
    $sig = base64_encode(hash_hmac('sha256', $request_body, $secret, true));
    
    if( !function_exists('apache_request_headers') ) {
      function apache_request_headers() {
        $headers = array();
        foreach($_SERVER as $key => $value) {
            if (substr($key, 0, 5) <> 'HTTP_') {
                continue;
            }
            $header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
            $headers[$header] = $value;
        }
        return $headers;
      }
    }
    $header = apache_request_headers(); 
    foreach ( $header as $headers => $value ) {
      if( $headers == 'X-Wc-Webhook-Signature' ) {
        if ( $value == $sig ) {
          $passed = true;
        }
      }
    }
    
    if( $passed !== true ) {
      header("Location: https://our-url.com");
    } else {
    
    $gx_url_1 = 'https://givexurl-1.com';
    $gx_url_2 = 'https://givexurl-2.com';
    $gx_port_1 = port;
    $gx_port_2 = port;
    $gx_post_url_1 = $gx_url_1 . ':' . $gx_port_1;
    $gx_post_url_2 = $gx_url_2 . ':' . $gx_port_2;
    $gx_user = 'user';
    $gx_password = 'pass';
    
    $data = json_decode(file_get_contents('php://input'), true);
    
    foreach( $data['line_items'] as $item ) {
      if( $item['product_id'] == 1457 ) {
        $item_meta_data_group = $item['meta_data'];
        $gift_card_data = array();
        foreach( $item_meta_data_group as $item_meta_data ) {
          $gift_card_data[$item_meta_data['key']] = $item_meta_data['value'];
        }
    
        $data_modified = array(
          'method' => '904',
          'params' => [
            'en',
            null,
            $gx_user,
            $gx_password,
            str_replace(array(',', '$', ' '), '', $gift_card_data['gift-card-amount']),
            null,
            null,
            null
          ],
          'id' => 'test'
        );
    
        $options = array(
          'http' => array(
            'method' => 'POST',
            'header' => 'Content-Type: application/json',
            'content' => json_encode( $data_modified )
          )
        );
    
        $context  = stream_context_create( $options );
        //$result = file_get_contents( $gx_post_url, false, $context );
        $result = file_get_contents( $gx_post_url_1, false, $context );
        if ( $result == false ) {
          $result = file_get_contents( $gx_post_url_2, false, $context );
        }
        $response = json_decode( $result );
        $response_reference = explode(':', $response->result[2]);
        echo $result;
    
        $to = $gift_card_data['recipient_email'];
        $subject_decoded = 'You received a gift card ';
        $subject = '=?UTF-8?B?' . base64_encode( $subject_decoded ) . '?=';
        $subject1 = 'test';
        $message = '<table border="0" cellspacing="0" cellpadding="0" width="100%" style="width: 100%; border-collapse: collapse;"><tbody><tr><td style="padding: 40px 40px 20px; background-color: #f9f9f9;" align="center"><table border="0" cellspacing="0" cellpadding="0" width="600" style="border-collapse: collapse;"><tbody>';
        $message .= '<tr><td align="center" valign="bottom" style="padding: 0 0 20px;">';
        $message .= '</td></tr>';
        $message .= '<tr><td align="center" style="padding: 10px 40px 20px; background-color: #ffffff; color: #676767; font-family: Helvetica, Arial, sans-serif;">';
        $message .= '<h2 style="font-family: Garamond, serif; font-size: 28px; font-weight: 600; color: #444444;">' . (!empty($gift_card_data['recipient_name']) ? $gift_card_data['recipient_name'] : 'Whoa') . ', you&rsquo;ve got ' . $gift_card_data['gift-card-amount'] . ' to spend at!</h2>';
        $message .= '<p style="color: #676767;">' . (!empty($gift_card_data['sender']) ? $gift_card_data['sender'] : 'Someone') . ' sent you a gift card' . (!empty($gift_card_data['message']) ? ' with the following message:' : '.') . '</p>';
        if( !empty($gift_card_data['message']) ) {
          $message .= '<p style="color: #676767;"><i><br />' . nl2br($gift_card_data['message']) . '<br /><br /></i></p>';
        }
        //$message .= '<img src="https://www.barcodesinc.com/generator/image.php?code=' . $response->result[3] . '&style=68&type=C39&width=300&height=50&xres=1&font=4" alt="" />';
        // barcode generator website: https://www.barcodesinc.com/generator/index.php
        $message .= '<p style="color: 676767; font-size: 1.25em;"><b>Card Number:</b> ' . $response->result[3] . '<br /> <b>PIN:</b> ' . $response_reference[1] . '<br /> <b>Card Amount:</b> ' . $response->result[4] . '<br /> <b>Reference Number:</b> ' . $response_reference[0] . '</p>';
        $message .= '</td></tr>';
        $message .= '<tr><td align="center" style="padding: 20px 0 0;">';
        $message .= '<p style="color: #676767;"><b>We look forward to you dining with us!</b></p>';  
        $message .= '</td></tr>';
        $message .= '</tbody></table></td></tr></tbody></table>';
        $headers = "From: Gift Cards <test.com>\r\n";
        $headers .= "Reply-To: noreply@test.com\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
        mail($to, $subject, $message, $headers);
      }
    } // end foreach
    
    } // end if else '$passed !== true'
    
    plugins/givex/webhook.php

     // Get grouped product ID from child product ID
     function get_parent_grouped_id( $children_id ){
         global $wpdb;
         $results = $wpdb->get_col("SELECT post_id FROM {$wpdb->prefix}postmeta
             WHERE meta_key = '_children' AND meta_value LIKE '%$children_id%'");
         // Will only return one product Id or false if there is zero or many
         return sizeof($results) == 1 ? reset($results) : false;
     }
     /**
      * add_new_topic_hooks will add a new webhook topic hook. 
      * @param array $topic_hooks Esxisting topic hooks.
      */
     function add_new_topic_hooks( $topic_hooks ) {
        // Array that has the topic as resource.event with arrays of actions that call that topic.
        $new_hooks = array(
            'order.gift_card' => array(
                'order_gift_card_filter',
                ),
            );
        return array_merge( $topic_hooks, $new_hooks );
     }
     add_filter( 'woocommerce_webhook_topic_hooks', 'add_new_topic_hooks' );
     /**
      * add_new_topic_events will add new events for topic resources.
      * @param array $topic_events Existing valid events for resources.
      */
     function add_new_topic_events( $topic_events ) {
        // New events to be used for resources.
        $new_events = array(
            'gift_card',
            );
        return array_merge( $topic_events, $new_events );
     }
     add_filter( 'woocommerce_valid_webhook_events', 'add_new_topic_events' );
     /**
      * add_new_webhook_topics adds the new webhook to the dropdown list on the Webhook page.
      * @param array $topics Array of topics with the i18n proper name.
      */
     function add_new_webhook_topics( $topics ) {
        // New topic array to add to the list, must match hooks being created.
        $new_topics = array( 
            'order.gift_card' => __( 'Order Gift Card', 'woocommerce' ),
            );
        return array_merge( $topics, $new_topics );
     }
     add_filter( 'woocommerce_webhook_topics', 'add_new_webhook_topics' );
     /**
      * my_order_item_check will check an order when it is created through the checkout form,
      * if it has product ID 1030 as one of the items, it will fire off the action `order_gift_card_filter`
      * 
      * @param  int    $order_id    The ID of the order that was just created.
      * @param  array  $posted_data Array of all of the data that was posted through checkout form.
      * @param  object $order       The order object.
      * @return null
      */
      function my_order_item_check( $order_id, $posted_data, $order ) {
        $order = wc_get_order( $order_id );
        $order_status = $order->status;
        $items = $order->get_items();
        foreach ( $items as $item ) {
    
            if ( is_a( $item, 'WC_Order_Item_Product' ) ) {
    
                if ( 1457 === $item->get_product_id() ) {
    
              $item_data = $item->get_data();
              $item_meta_data_group = $item_data['meta_data'];
              $gift_card_data = array();
              foreach ( $item_meta_data_group as $item_meta_data ) {
                $gift_card_data[$item_meta_data->key] = $item_meta_data->value;
              }
    
              do_action( 'order_gift_card_filter', $order_id, $posted_data, $order );
    
                }
            }
        }
      }
    
    //The two below actions are what the order.created webhook is tied into, it is up to you to use these if you wish. 
    
    //add_action( 'woocommerce_payment_complete', 'my_order_item_check', 10, 4 );
    add_action( 'woocommerce_checkout_order_processed', 'my_order_item_check', 10, 3 );
    //add_action( 'woocommerce_process_shop_order_meta', 'my_order_item_check', 10, 2 );
    
    add_action( 'wp_enqueue_scripts', 'add_ajax_script' );
    function add_ajax_script() {
      wp_enqueue_script( 'check-balance', plugins_url( '/check-balance.js', __FILE__ ), array('jquery'), '1.0', true );
      wp_enqueue_script( 'secure-register', plugins_url( '/secure-register.js', __FILE__ ), array('jquery'), '1.0', true );
      wp_localize_script( 'check-balance', 'gi_check_balance', array( 'ajax_url' => admin_url('admin-ajax.php') ) );
      wp_localize_script( 'secure-register', 'gi_secure_register', array( 'ajax_url' => admin_url('admin-ajax.php') ) );
    }
    
    add_action( 'wp_ajax_nopriv_gi_check_balance', 'gi_check_balance' );
    add_action( 'wp_ajax_gi_check_balance', 'gi_check_balance' );
    function gi_check_balance() {
      $gx_url_1 = 'https://givexurl-1.com';
      $gx_url_2 = 'https://givexurl-2.com';
      $gx_port_1 = port;
      $gx_port_2 = port;
      $gx_post_url_1 = $gx_url_1 . ':' . $gx_port_1;
      $gx_post_url_2 = $gx_url_2 . ':' . $gx_port_2;
      $gx_user = 'user';
      $gx_password = 'pass';
    
      $gx_card_number = $_POST['gx_card_number'];
    
      $data = array(
        'method' => '994',
        'params' => [
          'en',
          'rc1',
          //null,
          $gx_user,
          $gx_password,
          $gx_card_number,
          $gx_card_pin,
          null
        ],
        'id' => 'test'
      );
    
      $options = array(
        'http' => array(
          'method' => 'POST',
          'header' => 'Content-Type: application/json',
          'content' => json_encode( $data )
        )
      );
    
      $context  = stream_context_create( $options );
      $result = file_get_contents( $gx_post_url_1, false, $context );
      if ( $result == false ) {
        $result = file_get_contents( $gx_post_url_2, false, $context );
      }
      $response = json_decode( $result );
    
      echo $result;
      //echo json_encode($result) ;
      //var_dump( $response );
      //echo $response;
    
      die();
    }
    
    // function only for dev testing purposes
    //add_action( 'wp_ajax_gi_secure_register', 'gi_secure_register' );
    function gi_secure_register() {
      $gx_url_1 = 'https://givexurl-1.com';
      $gx_url_2 = 'https://givexurl-2.com';
      $gx_port_1 = port;
      $gx_port_2 = port;
      $gx_post_url_1 = $gx_url_1 . ':' . $gx_port_1;
      $gx_post_url_2 = $gx_url_2 . ':' . $gx_port_2;
      $gx_user = 'user';
      $gx_password = 'pass';
    
      $gx_register_amount = $_POST['gx_register_amount'];
    
      $data = array(
        'method' => '904',
        'params' => [
          'en',
          'rc2',
          //null,
          $gx_user,
          $gx_password,
          $gx_register_amount,
          null,
          null,
          null
        ],
        'id' => 'test'
      );
    
      $options = array(
        'http' => array(
          'method' => 'POST',
          'header' => 'Content-Type: application/json',
          'content' => json_encode( $data )
        )
      );
    
      $context  = stream_context_create( $options );
      $result = file_get_contents( $gx_post_url_1, false, $context );
      if ( $result == false ) {
        $result = file_get_contents( $gx_post_url_2, false, $context );
      }
      $response = json_decode( $result );
    
      echo json_encode($result);
    
      die();
    }
    
    <?php 
    // required headers
    header("Access-Control-Allow-Origin: *");
    header("Content-Type: application/json; charset=UTF-8");
    
    $passed = false;
    $request_body = file_get_contents('php://input');
    $secret = 'P&_(e>P _I?%/aOW?wv0H.U149+Eyv8bh~qXd<6XrIY8+K0oo]';
    $sig = base64_encode(hash_hmac('sha256', $request_body, $secret, true));
    
    if( !function_exists('apache_request_headers') ) {
      function apache_request_headers() {
        $headers = array();
        foreach($_SERVER as $key => $value) {
            if (substr($key, 0, 5) <> 'HTTP_') {
                continue;
            }
            $header = str_replace(' ', '-', ucwords(str_replace('_', ' ', strtolower(substr($key, 5)))));
            $headers[$header] = $value;
        }
        return $headers;
      }
    }
    $header = apache_request_headers(); 
    foreach ( $header as $headers => $value ) {
      if( $headers == 'X-Wc-Webhook-Signature' ) {
        if ( $value == $sig ) {
          $passed = true;
        }
      }
    }
    
    if( $passed !== true ) {
      header("Location: https://our-url.com");
    } else {
    
    $gx_url_1 = 'https://givexurl-1.com';
    $gx_url_2 = 'https://givexurl-2.com';
    $gx_port_1 = port;
    $gx_port_2 = port;
    $gx_post_url_1 = $gx_url_1 . ':' . $gx_port_1;
    $gx_post_url_2 = $gx_url_2 . ':' . $gx_port_2;
    $gx_user = 'user';
    $gx_password = 'pass';
    
    $data = json_decode(file_get_contents('php://input'), true);
    
    foreach( $data['line_items'] as $item ) {
      if( $item['product_id'] == 1457 ) {
        $item_meta_data_group = $item['meta_data'];
        $gift_card_data = array();
        foreach( $item_meta_data_group as $item_meta_data ) {
          $gift_card_data[$item_meta_data['key']] = $item_meta_data['value'];
        }
    
        $data_modified = array(
          'method' => '904',
          'params' => [
            'en',
            null,
            $gx_user,
            $gx_password,
            str_replace(array(',', '$', ' '), '', $gift_card_data['gift-card-amount']),
            null,
            null,
            null
          ],
          'id' => 'test'
        );
    
        $options = array(
          'http' => array(
            'method' => 'POST',
            'header' => 'Content-Type: application/json',
            'content' => json_encode( $data_modified )
          )
        );
    
        $context  = stream_context_create( $options );
        //$result = file_get_contents( $gx_post_url, false, $context );
        $result = file_get_contents( $gx_post_url_1, false, $context );
        if ( $result == false ) {
          $result = file_get_contents( $gx_post_url_2, false, $context );
        }
        $response = json_decode( $result );
        $response_reference = explode(':', $response->result[2]);
        echo $result;
    
        $to = $gift_card_data['recipient_email'];
        $subject_decoded = 'You received a gift card ';
        $subject = '=?UTF-8?B?' . base64_encode( $subject_decoded ) . '?=';
        $subject1 = 'test';
        $message = '<table border="0" cellspacing="0" cellpadding="0" width="100%" style="width: 100%; border-collapse: collapse;"><tbody><tr><td style="padding: 40px 40px 20px; background-color: #f9f9f9;" align="center"><table border="0" cellspacing="0" cellpadding="0" width="600" style="border-collapse: collapse;"><tbody>';
        $message .= '<tr><td align="center" valign="bottom" style="padding: 0 0 20px;">';
        $message .= '</td></tr>';
        $message .= '<tr><td align="center" style="padding: 10px 40px 20px; background-color: #ffffff; color: #676767; font-family: Helvetica, Arial, sans-serif;">';
        $message .= '<h2 style="font-family: Garamond, serif; font-size: 28px; font-weight: 600; color: #444444;">' . (!empty($gift_card_data['recipient_name']) ? $gift_card_data['recipient_name'] : 'Whoa') . ', you&rsquo;ve got ' . $gift_card_data['gift-card-amount'] . ' to spend at!</h2>';
        $message .= '<p style="color: #676767;">' . (!empty($gift_card_data['sender']) ? $gift_card_data['sender'] : 'Someone') . ' sent you a gift card' . (!empty($gift_card_data['message']) ? ' with the following message:' : '.') . '</p>';
        if( !empty($gift_card_data['message']) ) {
          $message .= '<p style="color: #676767;"><i><br />' . nl2br($gift_card_data['message']) . '<br /><br /></i></p>';
        }
        //$message .= '<img src="https://www.barcodesinc.com/generator/image.php?code=' . $response->result[3] . '&style=68&type=C39&width=300&height=50&xres=1&font=4" alt="" />';
        // barcode generator website: https://www.barcodesinc.com/generator/index.php
        $message .= '<p style="color: 676767; font-size: 1.25em;"><b>Card Number:</b> ' . $response->result[3] . '<br /> <b>PIN:</b> ' . $response_reference[1] . '<br /> <b>Card Amount:</b> ' . $response->result[4] . '<br /> <b>Reference Number:</b> ' . $response_reference[0] . '</p>';
        $message .= '</td></tr>';
        $message .= '<tr><td align="center" style="padding: 20px 0 0;">';
        $message .= '<p style="color: #676767;"><b>We look forward to you dining with us!</b></p>';  
        $message .= '</td></tr>';
        $message .= '</tbody></table></td></tr></tbody></table>';
        $headers = "From: Gift Cards <test.com>\r\n";
        $headers .= "Reply-To: noreply@test.com\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
        mail($to, $subject, $message, $headers);
      }
    } // end foreach
    
    } // end if else '$passed !== true'
    
    plugins/givex/secure register.js

       jQuery(document).ready(function($) {
    
          // checks card balance
          $('.gi-check-balance').submit(function() {
    
            var gx_card_number = $(this).find('[name=card-number]').val()
            var gx_card_pin = $(this).find('[name=card-pin]').val()
    
            $.ajax({
              url: gi_check_balance.ajax_url,
              type: 'post',
              data: {
                action: 'gi_check_balance',
                gx_card_number: gx_card_number,
                gx_card_pin: gx_card_pin
              },
              dataType: 'json',
              success: function(response) {
                console.log(response)
                $('.gi-check-balance-result').text(response['result'][2])
                //$('.gi-check-balance-result').text(JSON.stringify(response))
                $('.gi-check-balance-result').show()
              }
            })
    
            return false
    
          })
    
        })
    
    jQuery(document).ready(function($) {
    
      // registers gift card
      $('.gi-secure-register').submit(function() {
    
        var gx_register_amount = $(this).find('[name=register-amount]').val()
    
        $.ajax({
          url: gi_secure_register.ajax_url,
          type: 'post',
          data: {
            action: 'gi_secure_register',
            gx_register_amount: gx_register_amount
          },
          dataType: 'json',
          success: function(response) {
            //$('.gi-secure-register-result').html('Reference Number: ' + response['result'][2] + '<br>' + 'Card Number: ' + response['result'][3] + '<br>' + 'Card Amount: ' + response['result'][4])
            $('.gi-secure-register-result').text(response)
            $('.gi-secure-register-result').show();
            console.log(response);
          }
        })
    
        return false
    
      })
    
    })
    
    上面的错误在这里解决了,解决了我一直遇到的主要问题

  • 说到控制台日志记录,我使用
    error_log();
    然后查看PHP错误日志文件。 看

  • 当我想知道钩子在哪里使用时,我使用第一个字符串,
    “wp\u ajax\u gi\u check\u balance”
    ,在*.php文件中搜索整个网站(如果我知道在哪里查找的话,搜索更少),并查找一行写有
    do\u action(

  • 稍后我会发布更多

    更新

    我意识到我对你的其他问题并不比你更了解。我认为至少错误日志可以让你更深入地了解它是如何工作的。我现在要去睡觉了,但如果你有任何更新,我可能明天再检查

    更新2

    关于您的SSL错误:

    你试过自己用谷歌搜索错误吗

  • 说到控制台日志记录,我使用
    error_log();
    然后查看PHP错误日志文件。 看

  • 当我想知道钩子在哪里使用时,我使用第一个字符串,
    “wp\u ajax\u gi\u check\u balance”
    ,在*.php文件中搜索整个网站(如果我知道在哪里查找的话,搜索更少),并查找一行写有
    do\u action(

  • 稍后我会发布更多

    更新

    我意识到我对你的其他问题并不比你更了解。我认为至少错误日志可以让你更深入地了解它是如何工作的。我现在要去睡觉了,但如果你有任何更新,我可能明天再检查

    更新2

    关于您的SSL错误:


    你试过自己用谷歌搜索错误了吗?

    有太多的问题需要我的评论,我只回答一个问题:以
    wp\u ajax\u nopriv\u和
    wp\u ajax\u
    开头的钩子被触发了