Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/97.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/9/csharp-4.0/2.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
iOS Swift,Stripe createEphemeralKeys返回谷歌登录页面_Ios_Node.js_Swift_Stripe Payments_Google Cloud Functions - Fatal编程技术网

iOS Swift,Stripe createEphemeralKeys返回谷歌登录页面

iOS Swift,Stripe createEphemeralKeys返回谷歌登录页面,ios,node.js,swift,stripe-payments,google-cloud-functions,Ios,Node.js,Swift,Stripe Payments,Google Cloud Functions,嗨,我正在尝试使用Firebase云函数获取临时密钥,下面是我的Swift文件和节点文件 .swift class VIARestClient: NSObject, STPEphemeralKeyProvider { static let restClient = VIARestClient(); func createCustomerKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCom

嗨,我正在尝试使用Firebase云函数获取临时密钥,下面是我的Swift文件和节点文件

.swift

class VIARestClient: NSObject, STPEphemeralKeyProvider {

static let restClient = VIARestClient();

func createCustomerKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCompletionBlock) {

    let URLString = API_ENDPOINT + CREATE_EMPHEREMAL_KEY as String;

    let custID = "cus_CEPMtLbshv7EaP";        

    var requestData : [String : String]? = [String : String]()
    requestData?.updateValue(apiVersion, forKey: "api_version");
    requestData?.updateValue(custID, forKey: "customerId");

    submitDataToURL(URLString, withMethod: "POST", requestData: requestData!);

}



func submitDataToURL(_ urlString : String, withMethod method : String, requestData data : [String : Any]) {
    do {
        guard let url = URL(string: urlString) else {return};

        let defaultSession = URLSession(configuration: .default)

        var urlRequest = URLRequest(url: url, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 60)

        urlRequest.httpMethod = method;
        urlRequest.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")  // the request is JSON
        urlRequest.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Accept")        // the expected response is also JSON

        let httpBodyData : Data?

        try httpBodyData = JSONSerialization.data(withJSONObject: data, options: []);

        urlRequest.httpBody = httpBodyData;

        let dataTask = defaultSession.dataTask(with: urlRequest, completionHandler: { (responseData, urlResponse, error) in
            print("responseData \(String(describing: responseData))");

            print("urlResponse \(String(describing: urlResponse))");

        })

        dataTask.resume();
    }
    catch {
        print("Excetion in submitDataToURL")
    }   
}
nodejs

app.post('/createEphemeralKeys', (req, res) => {

  const stripe_version = req.body.api_version;
  if (!stripe_version) {
    res.status(400).end();
    return;
  }
  stripe.ephemeralKeys.create(
    {customer: req.body.customerId},
    {stripe_version: stripe_version}
  ).then((key) => {
    res.status(200).send(key);
  }).catch((err) => {
    res.status(500).end();
  });
});
当我执行RESTAPI调用时,我得到的响应是GoogleSigninURL,即使我在POSTMAN中尝试过,响应也是纯HTML文本。我正在使用
STPCustomerContext
STPPaymentContext
,这里的微调器继续旋转

这是xcode调试器中的日志

    (<NSHTTPURLResponse: 0x170237a20> { URL: https://accounts.google.com/ServiceLogin?service=ah&passive=true&continue=https%3A%2F%2Fappengine.google.com%2F_ah%2Fconflogin%3Fcontinue%3Dhttps%3A%2F%2Fus-central1-devdatabasefresh.cloudfunctions.net%2FcreateEphemeralKeys } { status code: 200, headers {
    "Cache-Control" = "no-cache, no-store, max-age=0, must-revalidate";
    "Content-Type" = "text/html; charset=UTF-8";
    Date = "Thu, 01 Feb 2018 17:44:46 GMT";
    Expires = "Mon, 01 Jan 1990 00:00:00 GMT";
    Pragma = "no-cache";
    Server = GSE;
    "Set-Cookie" = "GAPS=1:DPWaQyfDlbfYxiI2mrsbqszeoBaWZg:2mBfv5V9UXY2rkxf;Path=/;Expires=Sat, 01-Feb-2020 17:44:46 GMT;Secure;HttpOnly;Priority=HIGH";
    "Strict-Transport-Security" = "max-age=31536000; includeSubDomains";
    "alt-svc" = "hq=\":443\"; ma=2592000; quic=51303431; quic=51303339; quic=51303338; quic=51303337; quic=51303335,quic=\":443\"; ma=2592000; v=\"41,39,38,37,35\"";
    "content-security-policy" = "script-src 'nonce-Gb8VeHY/ULjN1Yy9ofK4/tWy+I0' 'unsafe-inline' 'strict-dynamic' https: http: 'unsafe-eval';object-src 'none';base-uri 'self';report-uri /cspreport";
    "x-auto-login" = "realm=com.google&args=service%3Dah%26continue%3Dhttps%253A%252F%252Fappengine.google.com%252F_ah%252Fconflogin%253Fcontinue%253Dhttps%253A%252F%252Fus-central1-devdatabasefresh.cloudfunctions.net%252FcreateEphemeralKeys";
    "x-content-type-options" = nosniff;
    "x-frame-options" = DENY;
    "x-xss-protection" = "1; mode=block";
} })
({URL:https://accounts.google.com/ServiceLogin?service=ah&passive=true&continue=https%3A%2F%2Fappengine.google.com%2F_ah%2Fconflogin%3Fcontinue%3Dhttps%3A%2F%2Fus-central1 devdatabasefresh.cloudfunctions.net%2FcreateEphemeralKeys}{状态代码:200,标题{
“缓存控制”=“无缓存,无存储,最大使用期限=0,必须重新验证”;
“内容类型”=“文本/html;字符集=UTF-8”;
日期=“2018年2月1日星期四17:44:46 GMT”;
Expires=“1990年1月1日星期一00:00:00 GMT”;
Pragma=“无缓存”;
服务器=GSE;
“设置Cookie”=“间隙=1:DPWaQyfDlbfYxiI2mrsbqszeoBaWZg:2mBfv5V9UXY2rkxf;路径=/;过期=周六,2020年2月1日17:44:46 GMT;安全;仅限HttpOnly;优先级=高”;
“严格的传输安全”=“最大年龄=31536000;包括子域”;
“alt svc”=“hq=\”:443\“ma=2592000;quic=51303431;quic=51303339;quic=51303338;quic=51303337;quic=51303335,quic=\”:443\“ma=2592000;v=”41,39,38,37,35\”;
“内容安全策略”=“脚本src'nonce-Gb8VeHY/uljn1yyy9ofk4/tWy+I0”“不安全内联”“严格动态”https:http:'safe eval';对象src'none';基uri'self';报告uri/cspreport”;
“x-auto-login”=“realm=com.google&args=service%3Dah%26继续%3Dhttps%253A%252F%252Fappengine.google.com%252F_-ah%252Fconflogin%253Fcontinue%253Dhttps%253A%252F%252Fus-central1-devdatabasefresh.cloudfunctions.net%252fCreatePheemeralkeys”;
“x-content-type-options”=nosniff;
“x帧选项”=拒绝;
“x-xss-protection”=“1;模式=块”;
} })
我跟踪了这段youtube视频

我试图使用阿拉莫菲尔的
.responseJSON
,但失败了


请让我知道我在哪里出错,否则任何提示/文档都将非常有用

我对nodejs代码的方法似乎不正确,因为我使用的是express,后来用下面的代码更改了代码实现

exports.createEphemeralKeys = functions.https.onRequest((req, res) => {
var api_version = req.body.api_version;
var customerId = req.body.customerId;

if (!api_version) {
  res.status(400).end();
  return;
}

stripe.ephemeralKeys.create(
  { customer: customerId },
  { stripe_version: api_version }, 

  function(err, key) {
    return res.send(key);
  });   
});
输出日志如下所示

{ 
  id: 'ephkey_1BramAFjruqsvjkVQGdZLiV5',
  object: 'ephemeral_key',
  associated_objects: [ { type: 'customer', id: 'cus_CEPMtLbshv7EaP' } ],
  created: 1517701830,
  expires: 1517705430,
  livemode: false,
  secret: 'ek_test_YWNjdF8xQmxUb0FGanJ1cXN2amtWLHVPcUdMN3d4UEhncW1sQkNJYmlOdzhwUGdjVUxOd1Y' 
}
swift文件如下所示

class VIARestClient: NSObject, STPEphemeralKeyProvider {

static let restClient = VIARestClient();

func createCustomerKey(withAPIVersion apiVersion: String, completion: @escaping STPJSONResponseCompletionBlock) {

    let URLString = API_ENDPOINT + CREATE_EMPHEREMAL_KEY as String;

    let custID = "cus_CEPMtLbshv7EaP";        

    var requestData : [String : String]? = [String : String]()
    requestData?.updateValue(apiVersion, forKey: "api_version");
    requestData?.updateValue(custID, forKey: "customerId");

    submitDataToURL(URLString, withMethod: "POST", requestData: requestData!) { (jsonResponse, err) in
        if err != nil {
            completion(nil, err)
        }
        else {
            completion(jsonResponse, nil)
        }
    }

}



func submitDataToURL(_ urlString : String, withMethod method : String, requestData data : [String : Any], completion : @escaping (_ jsonResponse : [String : Any], _ err: Error?) -> Void) {
    do {
        guard let url = URL(string: urlString) else {return};

        let defaultSession = URLSession(configuration: .default)

        var urlRequest = URLRequest(url: url, cachePolicy: .useProtocolCachePolicy, timeoutInterval: 60)

        urlRequest.httpMethod = method;
        urlRequest.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Content-Type")  // the request is JSON
        urlRequest.setValue("application/json; charset=utf-8", forHTTPHeaderField: "Accept")        // the expected response is also JSON

        let httpBodyData : Data?

        try httpBodyData = JSONSerialization.data(withJSONObject: data, options: []);

        urlRequest.httpBody = httpBodyData;

        let dataTask = defaultSession.dataTask(with: urlRequest, completionHandler: { (responseData, urlResponse, error) in
            print("responseData \(String(describing: responseData))");

            print("urlResponse \(String(describing: urlResponse))");

            if error == nil {
                do {
                    let response = try JSONSerialization.jsonObject(with: responseData!, options: []) as! [String : Any];
                    print(response);
                    completion(response, nil);
                }
                catch {
                    print("Exception")
                    let response : [String : Any] = [String : Any]()
                    completion(response, error);
                }
            }
            else {
                let response : [String : Any] = [String : Any]()
                completion(response, error);
            }
        });

        dataTask.resume();
    }
    catch {
        print("Excetion in submitDataToURL")
    }

  }
 }

从对cloud
createEphemeralKeys
函数的调用中,您得到了一个状态代码
200
。如果你进入Stripe dashboard,你会在“日志”部分下看到那些云请求的任何内容吗?Stripe dashboard节点是否有任何日志部分,我拿出Firebase云函数并在中使用POSTMAN
createEphemeralKeys
函数进行测试,有趣的是,控制在这两个
中都达到了({})
Clousure。我确实尝试过这个,但它对我不起作用,你是如何实现它并使它成功工作的?你是否在其他地方调用了
createCustomerKey
函数?不,
createCustomerKey
函数在协议
STPEphemeralKeyProvider
中,该协议负责触发它