- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我试图了解为什么有时 webhook 似乎会触发,而有时在 Woocommerce 购买后却不会触发。
有一个自定义插件应该添加到 custom topic
我对 woocommerce 插件 webhook 的理解是添加了以下代码(我将把整个代码放在下面)
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' );
<?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();
//$picnic_ordered_bool = false;
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 );
}
/*if ( '1611' === get_parent_grouped_id( $item->get_product_id() ) ) {
$item_data = $item->get_data();
$item_order_id = $item_data['order_id'];
$picnic_ordered_bool = true;
}*/
}
}
}
/**
* 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 = 'gift-card.com';
$gx_url_2 = 'gift-card-1.com';
$gx_port_1 = 54643;
$gx_port_2 = 432141;
$gx_post_url_1 = $gx_url_1 . ':' . $gx_port_1;
$gx_post_url_2 = $gx_url_2 . ':' . $gx_port_2;
$gx_user = '341241';
$gx_password = '432141';
$gx_card_number = $_POST['gx_card_number'];
/*$gx_card_pin = $_POST['gx_card_pin'];
if( empty($gx_card_pin) ) {
$gx_card_pin = 'XXXX';
}*/
$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();
}
<?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 = 'secret452323';
$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://dev-site.com");
} else {
/*$gx_url = 'https://dev-gift-card.com';
$gx_port = 50104;
$gx_post_url = $gx_url . ':' . $gx_port;
$gx_user = '423523';
$gx_password = 'hfja98eshj98234j';*/
$gx_url_1 = 'giftcard.com';
$gx_url_2 = 'giftcard-1.com';
$gx_port_1 = 45353;
$gx_port_2 = 43214;
$gx_post_url_1 = $gx_url_1 . ':' . $gx_port_1;
$gx_post_url_2 = $gx_url_2 . ':' . $gx_port_2;
$gx_user = '3424';
$gx_password = '38234287';
$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 = 'example@gmail.com';
$to = $gift_card_data['recipient_email'];
$subject_decoded = 'You received a gift card for Place | Deane House';
$subject = '=?UTF-8?B?' . base64_encode( $subject_decoded ) . '?=';
$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 .= '<img src="https://website.com/wp-content/uploads/2019/05/RCDH-ComLogo.png" alt="Place;"
width="600" height="87" style="vertical-align: bottom;" />';
$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’ve got ' . $gift_card_data['gift-card-amount'] . ' to spend at place</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://dev.website.com/wp-content/uploads/2019/06/rdch-gc.jpg" alt="" width="520" height="334" />';
//$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 <noreply@website.com>\r\n";
$headers .= "Reply-To: noreply@website.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'
?>
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()
}
})
return false
})
})
[10-Nov-2019 21:42:59 UTC] PHP 1. {main}() /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php:0
[10-Nov-2019 21:42:59 UTC] PHP 2. file_get_contents() /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php:86
[10-Nov-2019 21:42:59 UTC] PHP Warning: file_get_contents(): Failed to enable crypto in /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php on line 86
[10-Nov-2019 21:42:59 UTC] PHP Stack trace:
[10-Nov-2019 21:42:59 UTC] PHP 1. {main}() /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php:0
[10-Nov-2019 21:42:59 UTC] PHP 2. file_get_contents() /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php:86
[10-Nov-2019 21:42:59 UTC] PHP Warning: file_get_contents(https://dev-dataconnect.givex.com:50104): failed to open stream: operation failed in /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php on line 86
[10-Nov-2019 21:42:59 UTC] PHP Stack trace:
[10-Nov-2019 21:42:59 UTC] PHP 1. {main}() /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php:0
[10-Nov-2019 21:42:59 UTC] PHP 2. file_get_contents() /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php:86
[10-Nov-2019 21:42:59 UTC] PHP Notice: Trying to get property 'result' of non-object in /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php on line 92
[10-Nov-2019 21:42:59 UTC] PHP Stack trace:
[10-Nov-2019 21:42:59 UTC] PHP 1. {main}() /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php:0
[10-Nov-2019 21:42:59 UTC] PHP Notice: Trying to get property 'result' of non-object in /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php on line 112
[10-Nov-2019 21:42:59 UTC] PHP Stack trace:
[10-Nov-2019 21:42:59 UTC] PHP 1. {main}() /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php:0
[10-Nov-2019 21:42:59 UTC] PHP Notice: Trying to get property 'result' of non-object in /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php on line 112
[10-Nov-2019 21:42:59 UTC] PHP Stack trace:
[10-Nov-2019 21:42:59 UTC] PHP 1. {main}() /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php:0
[10-Nov-2019 21:42:59 UTC] PHP Notice: Undefined variable: mail in /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php on line 124
[10-Nov-2019 21:42:59 UTC] PHP Stack trace:
[10-Nov-2019 21:42:59 UTC] PHP 1. {main}() /Users/anderskitson/Local Sites/river-cafe/app/public/wp-content/plugins/givex-integrate/webhook.php:0
最佳答案
在 中检查您的日志输出第 86 行 警告 以。。开始:
file_get_contents(): Failed to enable crypto...
$options = array(
'ssl'=>array(
'verify_peer'=>false,
'verify_peer_name'=>false
),
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode( $data_modified )
)
);
empty()
在检查
$result
if ( empty($result) ) {
$result = file_get_contents( $gx_post_url_2, false, $context );
}
$options = array(
'ssl'=>array(
'verify_peer'=>true,
'verify_peer_name'=>true,
'cafile'=>'path/to/cafile.pem',
'CN_match'=>'demo.com',
'chiphers'=>'HIGH:!SSLv2:!SSLv3',
'disable_compression'=>true
),
'http' => array(
'method' => 'POST',
'header' => 'Content-Type: application/json',
'content' => json_encode( $data_modified )
)
);
关于php - 尝试在 woocommerce 中触发 webhook 后不发送电子邮件的原因跟踪错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58793737/
我在 JavaScript 文件中运行 PHP,例如...... var = '';). 我需要使用 JavaScript 来扫描字符串中的 PHP 定界符(打开和关闭 PHP 的 )。 我已经知道使
我希望能够做这样的事情: php --determine-oldest-supported-php-version test.php 并得到这个输出: 7.2 也就是说,php 二进制检查 test.
我正在开发一个目前不使用任何框架的大型 php 站点。我的大问题是,随着时间的推移慢慢尝试将框架融入应用程序是否可取,例如在创建的新部件和更新的旧部件中? 比如所有的页面都是直接通过url服务的,有几
下面是我的源代码,我想在同一页面顶部的另一个 php 脚本中使用位于底部 php 脚本的变量 $r1。我需要一个简单的解决方案来解决这个问题。我想在代码中存在的更新查询中使用该变量。 $name)
我正在制作一个网站,根据不同的情况进行大量 PHP 重定向。就像这样...... header("Location: somesite.com/redirectedpage.php"); 为了安全起见
我有一个旧网站,我的 php 标签从 因为短标签已经显示出安全问题,并且在未来的版本中将不被支持。 关于php - 如何避免在 php 文件中写入
我有一个用 PHP 编写的配置文件,如下所示, 所以我想用PHP开发一个接口(interface),它可以编辑文件值,如$WEBPATH , $ACCOUNTPATH和 const值(value)观
我试图制作一个登录页面来学习基本的PHP,首先我希望我的独立PHP文件存储HTML文件的输入(带有表单),但是当我按下按钮时(触发POST到PHP脚本) )我一直收到令人不愉快的错误。 我已经搜索了S
我正在寻找一种让 PHP 以一种形式打印任意数组的方法,我可以将该数组作为赋值包含在我的(测试)代码中。 print_r 产生例如: Array ( [0] => qsr-part:1285 [1]
这个问题已经有答案了: 已关闭11 年前。 Possible Duplicate: What is the max key size for an array in PHP? 正如标题所说,我想知道
我正在寻找一种让 PHP 以一种形式打印任意数组的方法,我可以将该数组作为赋值包含在我的(测试)代码中。 print_r 产生例如: Array ( [0] => qsr-part:1285 [1]
关闭。这个问题需要多问focused 。目前不接受答案。 想要改进此问题吗?更新问题,使其仅关注一个问题 editing this post . 已关闭 9 年前。 Improve this ques
我在 MySQL 数据库中有一个表,其中存储餐厅在每个工作日和时段提供的菜单。 表结构如下: i_type i_name i_cost i_day i_start i_
我有两页。 test1.php 和 test2.php。 我想做的就是在 test1.php 上点击提交,并将 test2.php 显示在 div 中。这实际上工作正常,但我需要向 test2.php
我得到了这个代码。我想通过textarea更新mysql。我在textarea中回显我的MySQL,但我不知道如何更新它,我应该把所有东西都放进去吗,因为_GET模式没有给我任何东西,我也尝试_GET
首先,我是 php 的新手,所以我仍在努力学习。我在 Wordpress 上创建了一个表单,我想将值插入一个表(data_test 表,我已经管理了),然后从 data_test 表中获取所有列(id
我有以下函数可以清理用户或网址的输入: function SanitizeString($var) { $var=stripslashes($var); $va
我有一个 html 页面,它使用 php 文件查询数据库,然后让用户登录,否则拒绝访问。我遇到的问题是它只是重定向到 php 文件的 url,并且从不对发生的事情提供反馈。这是我第一次使用 html、
我有一个页面充满了指向 pdf 的链接,我想跟踪哪些链接被单击。我以为我可以做如下的事情,但遇到了问题: query($sql); if($result){
我正在使用 从外部文本文件加载 HTML/PHP 代码 $f = fopen($filename, "r"); while ($line = fgets($f, 4096)) { print $l
我是一名优秀的程序员,十分优秀!