WooCommerce软件许可使用C#远程激活

时间:2016-11-21 02:04:30

标签: c# woocommerce

我正在尝试使用WooCommerce和WooCommerce Software Add-on远程激活许可证密钥。我正在使用C#编程来执行此功能,并且我已经在PHP中创建了激活器,因此所有程序都会将WebRequest发送到填充必填字段。我不确定为什么当程序说它发送了POST请求时它没有激活。如果我使用浏览器进行POST,它会激活许可证密钥,但通过程序它不会执行任何操作..

POST请求:

private void SubmitData()
        {
            try
            {
                string licensekey = licensekeyTXT.Text;
                string email = emailTXT.Text;

                var encoding = new ASCIIEncoding();
                var postData = "key=" + licensekey + "&email=" + email;
                var data = encoding.GetBytes(postData);

                var request = WebRequest.Create("https://varietysplaza.xyz/rcontent/activation.php");
                request.Method = "POST";
                request.ContentType = "application/x-www-form-urlencoded";
                request.ContentLength = data.Length;

                var stream = request.GetRequestStream();
                stream.Write(data, 0, data.Length);
                stream.Close();

                var response = request.GetResponse();
                stream = response.GetResponseStream();

                var sr = new StreamReader(stream);
                MessageBox.Show(sr.ReadToEnd());

                sr.Close();
                stream.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error : " + ex.Message);
            }

Activation.php:

<?php
$wp_root = "/home/varietysplaza/public_html";
if ( file_exists( $wp_root . '/wp-load.php' ) ) {
    require_once( $wp_root . "/wp-load.php" );
} else {
    exit;
}
if ( ! current_user_can( 'manage_options' ) ) die();
include( 'productsettings.php' );
// Fire away!
function execute_request( $args ) {
    $target_url = create_url( $args );
    $data = wp_remote_get( $target_url );
    var_dump( $data['body'] );
}
// Create an url based on
function create_url( $args ) {
    global $base_url;
    $base_url = add_query_arg( 'wc-api', 'software-api', $base_url );
    return $base_url . '&' . http_build_query( $args );
}
$license_key = $_GET['key'];
$email = $_GET['email'];
$args = array(
    'request'     => 'activation',
    'email'       => $email,
    'license_key' => $license_key,
    'product_id'  => $product_id,
    'secret_key'  => $secret_key,
    'instance'    => $instance
);
echo '<b>Valid activation request:</b><br />';
execute_request( $args );

0 个答案:

没有答案