Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/http/4.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angular/30.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
将woocommerce rest api v1与http和javascript(非https)一起使用_Http_Angular_Oauth_Woocommerce Rest Api_Oauth 1.0a - Fatal编程技术网

将woocommerce rest api v1与http和javascript(非https)一起使用

将woocommerce rest api v1与http和javascript(非https)一起使用,http,angular,oauth,woocommerce-rest-api,oauth-1.0a,Http,Angular,Oauth,Woocommerce Rest Api,Oauth 1.0a,我用它来生成我的oauth签名以连接WooCommerceAPI。我遵循了以下所述的所有步骤: 所需参数为:oauth\u消费者密钥、oauth\u时间戳、oauth\u nonce、oauth\u签名和oauth\u签名方法。oauth_版本不是必需的,应该省略。 OAuth nonce可以是任何随机生成的32个字符(推荐)的字符串,该字符串对于使用者密钥是唯一的。等等 但以下请求仍然返回未经授权的: (别担心,钥匙只供本地使用) 答复: {"code":"woocommerce_rest_

我用它来生成我的oauth签名以连接WooCommerceAPI。我遵循了以下所述的所有步骤:

所需参数为:oauth\u消费者密钥、oauth\u时间戳、oauth\u nonce、oauth\u签名和oauth\u签名方法。oauth_版本不是必需的,应该省略。 OAuth nonce可以是任何随机生成的32个字符(推荐)的字符串,该字符串对于使用者密钥是唯一的。等等

但以下请求仍然返回未经授权的:

(别担心,钥匙只供本地使用)

答复:

{"code":"woocommerce_rest_cannot_view","message":"Beklager, du kan ikke liste ressurser.","data":{"status":401}}
Im使用WP 4.7、WC 2.6.9、为WC激活API、为WC禁用SSL等

我还检查了是否按照库的要求执行此操作:

使用HMAC-SHA1哈希算法,使用签名基字符串和带有&字符的消费者密钥生成签名

时区是UNIX,应根据需要生成nonce。你们中的一些人发现问题了吗?这是我的密码:

constructor(private http: Http) {

    var d = new Date();
    var httpMethod = 'GET',
        url = 'http://siglar.no/wp-json/wc/v1/orders',
        ck = 'ck_1ca1c6ff1a93de4836ee52c766538043d7f15d07',
        cs = 'cs_ce323425064c37688d614e4ff43a5489c6f78017',
        sm = 'HMAC-SHA1',
        nc = this.nonceGen(),
        timestamp = Math.floor(d.getTime()/ 1000),
        parameters = {
            oauth_consumer_key : ck,
            oauth_timestamp : timestamp,
            oauth_nonce : nc,
            oauth_signature_method : sm
        },
        // generates a RFC 3986 encoded, BASE64 encoded HMAC-SHA1 hash
        encodedSignature = oauthSignature.generate(httpMethod, url, parameters, cs);

    this.http.get(
        url + '?oauth_consumer_key='+ck+'&oauth_timestamp='+timestamp+'&oauth_nonce='+nc+'&oauth_signature='+encodedSignature+'&oauth_signature_method='+sm
    ).subscribe(data => {
        console.log('fetched');
        console.log(data);
    });

}

public nonceGen() {
    let length = 32;
    let text = "";
    let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
    for(let i = 0; i < length; i++) {
        text += possible.charAt(Math.floor(Math.random() * possible.length));
    }
    return text;
}
构造函数(私有http:http){
var d=新日期();
var httpMethod='GET',
url='1〕http://siglar.no/wp-json/wc/v1/orders',
ck='ck_1ca1c6ff1a93de4836ee52c766538043d7f15d07',
cs='CSCE323425064C37688D614E4FF43A5489C6F78017',
sm='HMAC-SHA1',
nc=this.nonceGen(),
timestamp=Math.floor(d.getTime()/1000),
参数={
oauth_消费者_密钥:ck,
oauth_时间戳:时间戳,
非统组织:北卡罗来纳州,
oauth_签名_方法:sm
},
//生成RFC 3986编码、BASE64编码的HMAC-SHA1哈希
encodedSignature=oauthSignature.generate(httpMethod、url、参数、cs);
这是http.get(
url+'?oauth_consumer_key='+ck+'&oauth_timestamp='+timestamp+'&oauth_nonce='+nc+'&oauth_签名='+encodedSignature+'&oauth_签名方法='+sm
).订阅(数据=>{
log('fetched');
控制台日志(数据);
});
}
公共非政府组织(){
设长度=32;
让文本=”;
允许=“ABCDEFGHIJKLMNOPQRSTUVXYZABCDFGHIJKLMNOPQRSTUVXYZ0123456789”;
for(设i=0;i

其他人对此有什么运气吗?

我终于让它工作了

不知何故,它对我本地的wordpress安装不起作用,但对我的live wordpress站点起作用:

角度2代码:

constructor(private http: Http) {

    var oauth = OAuth({
        consumer: {
            key: 'ck_...',
            secret: 'cs_...'
        },
        signature_method: 'HMAC-SHA1',
        hash_function: function(base_string, key) {
            return CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(base_string, key));
        }
    });

    var requestData = {
        url: 'http://siglarweb.no/wp-json/wc/v1/orders',
        method: 'GET'
    };

    this.http.get(
        requestData.url + '?' + jQuery.param(oauth.authorize(requestData))
    ).subscribe(data => {
        console.log(data);
    });

}
"scripts": [
    "../node_modules/crypto-js/crypto-js.js",
    "../node_modules/oauth-1.0a/oauth-1.0a.js"
  ]
使用的库(通过npm安装):

constructor(private http: Http) {

    var oauth = OAuth({
        consumer: {
            key: 'ck_...',
            secret: 'cs_...'
        },
        signature_method: 'HMAC-SHA1',
        hash_function: function(base_string, key) {
            return CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(base_string, key));
        }
    });

    var requestData = {
        url: 'http://siglarweb.no/wp-json/wc/v1/orders',
        method: 'GET'
    };

    this.http.get(
        requestData.url + '?' + jQuery.param(oauth.authorize(requestData))
    ).subscribe(data => {
        console.log(data);
    });

}
"scripts": [
    "../node_modules/crypto-js/crypto-js.js",
    "../node_modules/oauth-1.0a/oauth-1.0a.js"
  ]
npm安装crypto js--保存 npm安装oauth-1.0a--保存

所需文件:

constructor(private http: Http) {

    var oauth = OAuth({
        consumer: {
            key: 'ck_...',
            secret: 'cs_...'
        },
        signature_method: 'HMAC-SHA1',
        hash_function: function(base_string, key) {
            return CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(base_string, key));
        }
    });

    var requestData = {
        url: 'http://siglarweb.no/wp-json/wc/v1/orders',
        method: 'GET'
    };

    this.http.get(
        requestData.url + '?' + jQuery.param(oauth.authorize(requestData))
    ).subscribe(data => {
        console.log(data);
    });

}
"scripts": [
    "../node_modules/crypto-js/crypto-js.js",
    "../node_modules/oauth-1.0a/oauth-1.0a.js"
  ]

我终于让它工作了

不知何故,它对我本地的wordpress安装不起作用,但对我的live wordpress站点起作用:

角度2代码:

constructor(private http: Http) {

    var oauth = OAuth({
        consumer: {
            key: 'ck_...',
            secret: 'cs_...'
        },
        signature_method: 'HMAC-SHA1',
        hash_function: function(base_string, key) {
            return CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(base_string, key));
        }
    });

    var requestData = {
        url: 'http://siglarweb.no/wp-json/wc/v1/orders',
        method: 'GET'
    };

    this.http.get(
        requestData.url + '?' + jQuery.param(oauth.authorize(requestData))
    ).subscribe(data => {
        console.log(data);
    });

}
"scripts": [
    "../node_modules/crypto-js/crypto-js.js",
    "../node_modules/oauth-1.0a/oauth-1.0a.js"
  ]
使用的库(通过npm安装):

constructor(private http: Http) {

    var oauth = OAuth({
        consumer: {
            key: 'ck_...',
            secret: 'cs_...'
        },
        signature_method: 'HMAC-SHA1',
        hash_function: function(base_string, key) {
            return CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(base_string, key));
        }
    });

    var requestData = {
        url: 'http://siglarweb.no/wp-json/wc/v1/orders',
        method: 'GET'
    };

    this.http.get(
        requestData.url + '?' + jQuery.param(oauth.authorize(requestData))
    ).subscribe(data => {
        console.log(data);
    });

}
"scripts": [
    "../node_modules/crypto-js/crypto-js.js",
    "../node_modules/oauth-1.0a/oauth-1.0a.js"
  ]
npm安装crypto js--保存 npm安装oauth-1.0a--保存

所需文件:

constructor(private http: Http) {

    var oauth = OAuth({
        consumer: {
            key: 'ck_...',
            secret: 'cs_...'
        },
        signature_method: 'HMAC-SHA1',
        hash_function: function(base_string, key) {
            return CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA1(base_string, key));
        }
    });

    var requestData = {
        url: 'http://siglarweb.no/wp-json/wc/v1/orders',
        method: 'GET'
    };

    this.http.get(
        requestData.url + '?' + jQuery.param(oauth.authorize(requestData))
    ).subscribe(data => {
        console.log(data);
    });

}
"scripts": [
    "../node_modules/crypto-js/crypto-js.js",
    "../node_modules/oauth-1.0a/oauth-1.0a.js"
  ]

我们遇到了
401未经授权的
响应问题,响应代码为
woocommerce\u rest\u无效\u签名


结果表明,我们在散列时使用的URL与我们访问的URL不同,散列中使用的URL缺少尾部斜杠。

我们遇到了一个
401未经授权的
响应问题,响应代码为
woocommerce\u rest\u invalid\u signature


结果是,我们在哈希时使用的URL与我们访问的URL不同,哈希中使用的URL缺少尾部斜杠。

我在这里找到了一个“不起作用”的解决方案:但这对我不起作用。quote=>“我用这个替换了line.\u key=ConsumerCret;”(看起来他使用的是wc api'legacy v2',我使用的是'v1',这是最新的)^我在这里找到了一个“不起作用”的解决方案:但这对我不起作用。quote=>“我用这个替换了行。_key=ConsumerCret;”(看起来他使用的是wc api“legacy v2”,我使用的是最新版本的“v1”)^如何在ts文件中导入加密和0auth?(很抱歉问这个新手问题)@GY22-
npm安装crypto js oauth-1.0a——保存
,然后在index.html中包含核心js文件或使用angular cli加载它们config@Steffan.can请说明如何使用oauth1.0a和crypto js发布数据Angular2@AISUNDAR这取决于RESTAPI服务器。只需使用普通的ajax请求,并遵循oauthbible.com了解授权方式。Jquerys ajax端点工作正常..如何在ts文件中导入加密和0auth?(很抱歉问这个新手问题)@GY22-
npm安装crypto js oauth-1.0a——保存
,然后在index.html中包含核心js文件或使用angular cli加载它们config@Steffan.can请说明如何使用oauth1.0a和crypto js发布数据Angular2@AISUNDAR这取决于RESTAPI服务器。只需使用普通的ajax请求,并遵循oauthbible.com了解授权方式。jQuerysAjax端点工作正常。。