有没有用php接入过谷歌支付,需要怎么对接

有没有用php接入过谷歌支付,需要怎么对接

《L03 构架 API 服务器》
你将学到如 RESTFul 设计风格、PostMan 的使用、OAuth 流程,JWT 概念及使用 和 API 开发相关的进阶知识。
《L02 从零构建论坛系统》
以构建论坛项目 LaraBBS 为线索,展开对 Laravel 框架的全面学习。应用程序架构思路贴近 Laravel 框架的设计哲学。
讨论数量: 2

谷歌支付需要海外账户和公司主体,有多货币结算和单位,得是外网IP访问调试才行

6天前 评论

以前调过相关,贴下

  1. 获取code
  2. 获取token

```php

方法1

accounts.google.com/o/oauth2/v2/au...

方法2

accounts.google.com/o/oauth2/v2/au...

access_type=offline
response_type=code
redirect_uri={your_redirect_uri}
client_id={your_client_id}
scope=www.googleapis.com/auth/androidpub...

跳转至如下地址

your_redirect_uri?code=4/0AWtgzh4lsFpIOSc61vKAvfwOtXIjp7WV5dAb9haMIqSeyXf_40HfGqvpBNxdcsHVcUoaFA&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fandroidpublisher

得到code

4/0AWtgzh4lsFpIOSc61vKAvfwOtXIjp7WV5dAb9haMIqSeyXf_40HfGqvpBNxdcsHVcUoaFA

```php

获取token方式1:

POST /token HTTP/1.1
Host: oauth2.googleapis.com
Content-Type: application/x-www-form-urlencoded

code=4/P7q7W91a-oMsCeLvIaQm6bTrgtp7&
client_id={your-client-id}&
client_secret={your-client-secret}&
redirect_uri={you_url}&
grant_type=authorization_code

获取token方式2:

POST /token HTTP/1.1
Host: oauth2.googleapis.com
Content-Type: application/x-www-form-urlencoded

client_id={your-client-id}&
client_secret={your-client-secret}&
grant_type=refresh_token&
refresh_token={you_refresh_token}

```shell

一些错误,以及参考文章

问题1

第一次获取refresh_token,过了几天又失效了,报错如下
“error”: “invalid_grant”,
“error_description”: “Token has been expired or revoked.”

问题2

查询google订单信息,报错大概就是权限问题
{
“error”: {
“code”: 401,
“message”: “The current user has insufficient permissions to perform the requested operation.”,
“errors”: [
{
“message”: “The current user has insufficient permissions to perform the requested operation.”,
“domain”: “androidpublisher”,
“reason”: “permissionDenied”
}
]
}
}

问题3

redirect_uri_mismatch

问题4

直接postman请求获取token可以通,放到代码本地调试443,放到服务器可以(国外服务器,国内没测试)
cURL error 7: Failed to connect to accounts.google.com port 443: Timed out (see curl.haxx.se/libcurl/c/libcurl-err...) for accounts.google.com/o/oauth2/token...

问题5

refresh_token过期,app在测试阶段授权获取的refresh_token只有七天有效,转正式后永久有效(这个还没测)
“error”: “invalid_grant”,
“error_description”: “Token has been expired or revoked.”

“error”: “invalid_grant”,
“error_description”: “Bad Request”

“error”: “invalid_grant”,
“error_description”: “Malformed auth code.”

相关错误资料说明

github.com/googleapis/google-api-n...

stackoverflow.com/questions/435369...

blog.csdn.net/qq_37611096/article/...

1天前 评论

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!