WooCommerce如何接收WebHooks数据?

时间:2018-07-28 08:19:17

标签: woocommerce webhooks

我是WooCommerce WebHooks开发的新手。

  • 我启用woocommerce rest api
  • 在订单创建上创建webhook操作。
  • 设置操作网址。

我还尝试将Webhooks触发值保存到文件中。

public class Program : IComparable
{
    public static void Main(string[] args)
    {
        var newList = new List<Object>();
        newList.Add(new Program { carName = "mercedes benz", topSpeed = 160 });
        newList.Add(new SecondClass { carName = "BMW", topSpeed = 140 });
        newList.Sort();

        foreach (var list in newList)
        {
             Console.WriteLine(list.carName + " " + list.topSpeed);
             /* Getting an error on this line stating 'object' does not contain a definition for 'carName' and no extension method 'carName' accepting a first argument of type 'object' could be found (are you missing a using directive or an assembly reference?)*/
        }
    }

    public string carName { get; set; }
    public int topSpeed   { get; set; }

    public int CompareTo(Object obj)
    {
        Program classObject = (Program)obj;

        if (this.topSpeed > classObject.topSpeed)
            return 1;
        else if (this.topSpeed == classObject.topSpeed)
             return 0;
        else return -1;
    }
}

public class SecondClass
{
    public string carName { get; set; }
    public int topSpeed   { get; set; }
}

/* Edit: implemented abstract class however I am getting this "Unhandled Exception Message": System.InvalidCastException: Unable to cast object of type 'CSharpbasics.SecondClass' to type 'CSharpbasics.Program'.*/

public class SecondClass : Car { }

public abstract class Car : IComparable
{
    public string carName { get; set; }
    public int topSpeed   { get; set; }

    public int CompareTo(Object obj)
    {
        Program classObject = (Program)obj;

        if (this.topSpeed > classObject.topSpeed)
            return 1;
        else if (this.topSpeed == classObject.topSpeed)
             return 0;
        else return -1;
    }
}

public class Program : Car
{
    static void Main(string[] args)
    {
        var newList = new List<Car>();
        newList.Add(new Program { carName = "Wagon R", topSpeed = 160 });
        newList.Add(new SecondClass { carName = "Swift", topSpeed = 140 });

        newList.Sort();

        foreach (var list in newList) 
            Console.WriteLine($"{list.carName} {list.topSpeed});
    }
}

但是我没有触发我的代码。

1 个答案:

答案 0 :(得分:0)

解决了:

<?php
$webhookContent = "";



$myfile = fopen("newfile.txt", "w") or die("Unable to open file!");

$webhook = fopen('php://input' , 'rb');
    while (!feof($webhook)) {
        $webhookContent .= fread($webhook, 4096);
    }


$txt = $webhookContent;
fwrite($myfile, $txt);

fclose($myfile);

?>