简体   繁体   English

VueJS + Gravity Forms API

[英]VueJS + Gravity Forms API

I'm looking at integrating a VueJS project with Gravity Forms, however I don't know how to trigger the GF encryption require by their API from the VueJS project? 我正在考虑将VueJS项目与Gravity Forms集成在一起,但是我不知道如何触发VueJS项目中其API要求的GF加密?

As outlined below, the signature needs to be calculated first, before values are attached and sent to the GF API. 如下所述,在将值附加并发送到GF API之前,需要首先计算签名。

function CalculateSig(stringToSign, privateKey){
//calculate the signature needed for authentication
var hash = CryptoJS.HmacSHA1(stringToSign, privateKey);
var base64 = hash.toString(CryptoJS.enc.Base64);
return encodeURIComponent(base64);
}

//set variables
var d = new Date;
var expiration = 3600; // 1 hour,
var unixtime = parseInt(d.getTime() / 1000);
var future_unixtime = unixtime + expiration;
var publicKey = "KEY HERE";
var privateKey = "KEY HERE";
var method = "POST";
var route = "forms/2/submissions";

stringToSign = publicKey + ":" + method + ":" + route + ":" +    future_unixtime;
sig = CalculateSig(stringToSign, privateKey);
var url = 'http://stephenkempin.co.uk/vuejs/gravityformsapi/' + route + '?api_key=' + publicKey + '&signature=' + sig + '&expires=' + future_unixtime;

var values = {input_values : {
                          input_1 : 'Name',
                          input_2 : 'This is surname',
                          input_5 : 'email@Address.com',
                          input_4 : 'Message testing'
                        }

    }

You should have a server that will make the API request for you. 您应该有一台可以为您发出API请求的服务器。 Do not put this in exposed FE code as it's easily viewed by the public. 不要将其放在公开的FE代码中,因为它很容易被公众查看。

The safe way to do it would be: 安全的方法是:

FrontEnd VueJS project -> make API request to your server (backend) -> makes API request to Gravity Forms using the private key. FrontEnd VueJS项目->向您的服务器(后端)发出API请求->使用私钥向Gravity Forms发出API请求。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM