原文链接: https://my.oschina.net/lemonzone2010/blog/398736

Google支付问题

20150218,挂机的日本服务器出现google支付被刷单现象,虽然目前进行的修补,但是这个问题并没有完全从根源上解决。并且公司以前的GooglePlay支付也有不完善的地方,在SDK端给支付回调发送支付信息后,支付回调程序没有调用Google API进行订单验证。因此Google支付流程需要进行完善。

Google支付解决方案

上面的支付问题,Google有自己的解决方案,就是根据订单号去向Google API发送验证申请,Google API会返回订单相关信息。可以根据这个信息和SDK返回的信息进行对比验证。

对于申请Google账号之类的流程,相信运营已经很清楚了,但是使用Google API还需要使用Google Developer Console创建Web Application账户,而后获取到client_id、client_secret、refresh_token。具体流程见下面:

1.       登陆 Google Developer Console ,地址:https://console.developers.google.com/cloud-resource-manager

2.       先点击CREATE PROJECT创建一个项目

3、再点击APIs & Service ,Create credentials,

先 set a product name on the consent screen,创建完成以后再创建Web application。(实际创建过程跟原文链接有部分不同)

其中4的地址一定是 可用域名 + /oauth2callback

创建完后,可以获得,client_id, client_secret, redirect_url

3.       获取Authorization code

google中心在登陆状态,打开新页面输入如下地址:

https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri={REDIRECT_URIS}&client_id={CLIENT_ID}

将蓝色部分根据相应的值进行替换;

这时会提示你是否要授权,点击授权,url地址栏会自动跳转,之后会获得code例如:https://www.example.com/oauth2callback?code=4/CpVOd8CljO_gxTRE1M5jtwEFwf8gRD44vrmKNDi4GSS.kr-GHuseD-oZEnp6UADFXm0E0MD3FlAI

4.       利用code获取refresh_token, 这里需要post请求

请求地址:https://accounts.google.com/o/oauth2/token

请求参数:code, client_id, client_secret, redirect_uri, grant_type

其中 grant_type 值为 authorization_code

第一次发起请求得到的JSON字符串如下所示,以后再请求将不再出现refresh_token(长令牌,一般不会失效),需要保存好refresh_token,可以存放到配置文件(或者写到数据库),以备后用

expires_in是指access_token的时效,为3600秒

{

"access_token": "ya29.3gC2jw5vm77YPkylq0H5sPJeJJDHX93Kq8qZHRJaMlknwJ85595eMogL300XKDOEI7zIsdeFEPY6zg",

"token_type": "Bearer",

"expires_in": 3600,

"refresh_token": "1/FbQD448CdDPfDEDpCy4gj_m3WDr_M0U5WupquXL_o"

}

在获取到client_id、client_secret、refresh_token后,我们的支付回调程序就可以使用订单号去请求Google Api进行验证。

Google支付回调验证流程

通过上一步获取到client_id、client_secret、refresh_token之后,支付回调程序就可以调用google api进行支付验证。具体流程如下:

1.       获取access_token。

请求地址:https://accounts.google.com/o/oauth2/token
请求方式:post
请求参数:client_id, client_secret, refresh_toke, grant_type
grant_type 值固定为 refresh_token
返回:json

Using the refresh token

Each access token is only valid for a short time. Once the current access token expires, the server will need to use the refresh token to get a new one. To do this, send a POST request to https://accounts.google.com/o/oauth2/tokenwith the following fields set:

grant_type=refresh_token
client_id=<the client ID token created in the APIs Console>
client_secret=<the client secret corresponding to the client ID>
refresh_token=<the refresh token from the previous step>

A successful response will contain another access token:

{"access_token" : "ya29.AHES3ZQ_MbZCwac9TBWIbjW5ilJkXvLTeSl530Na2","token_type" : "Bearer","expires_in" : 3600,
}

The refresh token thus allows a web server continual access to the API without requiring an active login to a Google account.

2.       通过获得access_token 就可以请求谷歌的 API 接口,获得订单状态

在这里我所需要获取的是我在应用内给GooglePlay支付的购买信息,此类信息包含以下几个属性:(可参考Google Play Developer API下的Purchases.products)

A ProductPurchase resource indicates the status of a user's inapp product purchase.

请求接口:https://www.googleapis.com/androidpublisher/v2/applications/packageName/purchases/products/productId/tokens/purchaseToken?access_token=access_token

     
packageName The package name of the application the inapp product was sold in (for example, 'com.some.thing').  
productId

The inapp product SKU (for example, 'com.some.thing.inapp1').

purchaseToken The token provided to the user's device when the inapp product was purchased. 就是订单中purchaseToken  
     
     
     

返回数据

1

2

3

4

5

6

7

<code class="hljs json">{

  <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">"kind"</span>: <span class="hljs-string"><span class="hljs-string"><span class="hljs-string">"androidpublisher#productPurchase"</span>,

  <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">"purchaseTimeMillis"</span>: long,

  <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">"purchaseState"</span>: integer,

  <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">"consumptionState"</span>: integer,

  <span class="hljs-attr"><span class="hljs-attr"><span class="hljs-attr">"developerPayload"</span>: string

}</span></span></span></span></span></span></span></span></span></span></span></span></code>

consumptionState integer The consumption state of the inapp product. Possible values are:

  1. 0:Yet to be consumed
  2. 1:Consumed
 
developerPayload string A developer-specified string that contains supplemental information about an order.  
kind string This kind represents an inappPurchase object in the androidpublisher service.  
purchaseState integer The purchase state of the order. Possible values are:

  1. 0:Purchased
  2. 1:Cancelled 我们就是依靠这个判断购买信息
 
purchaseTimeMillis long The time the product was purchased, in milliseconds since the epoch (Jan 1, 1970).  

到此支付验证完成!

参考文档:

http://blog.csdn.net/hjun01/article/details/42032841

http://www.vimer.cn/2014/04/google%E6%94%AF%E4%BB%98%E6%8E%A5%E5%8F%A3%E8%A2%AB%E5%88%B7%E4%BB%A5%E5%8F%8A%E8%A7%A3%E5%86%B3%E6%96%B9%E6%A1%88.html

调用接口遇到的几个问题:

1. Access Not Configured.

{

"error": {

"errors": [

{

"domain": "usageLimits",

"reason": "accessNotConfigured",

"message": "Access Not Configured. The API(Google Play Android Developer API)is not enabled for you project.Please use Google Developers Console to update your configuration."

}

],

"code": 403,

"message": "Access Not Configured. The API(Google Play Android Developer API)is not enabled for you project.Please use Google Developers Console to update your configuration."

}

}

在这个页面: https://console.developers.google.com  

Google Developer Console

1.  "Google Developer Console" > "APIs & Auth" subcategory "APIs" > (api list) "Google Play Android Developer API". Set "STATUS" to "ON".

2.  "APIs & auth" subcategory "Credentials" > "Create new Client ID". Choose "Service account" and create the id.

3.  You should get a P12 key from the browser.

问题2: projectNotLinked

{
    "error": {
        "errors": [
            {
                "domain": "androidpublisher",
                "reason": "projectNotLinked",
                "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."
            }
        ],
        "code": 403,
        "message": "The project id used to call the Google Play Developer API has not been linked in the Google Play Developer Console."
    }
}

在这个页设置关联:https://play.google.com/apps/publish/

Google Play Developer Console

1.  "Google Play Developer Console" > "Settings" > subcategory "API access".

2.  Make a link to your "Linked Project".

3.  "Service Account" place maybe already showing ur "Service account" CLIENT ID which made "google developer console".

google支付回调验证相关推荐

  1. php 微信支付md5签名,微信支付回调验证签名处理

    微信支付回调验证签名:一定要验证签名,可能不造成伪造数据,或者数据库造到灌水: /** * 微信支付回调类 * @name callbackaction.class.php * @author yan ...

  2. php微信回调验证签名,微信支付回调验证签名处理

    <?php /** * 微信支付回调类 * @name CallbackAction.class.php * @author yangzl * @date(20180820) */ class ...

  3. 银联电子支付ChinaPay支付回调验证问题

    注意是ChinaPay,银联电子支付,不是UnionPay,不是银联支付,详情请参考这篇文章 https://www.cnblogs.com/qidian10/p/4885038.html 支付回调验 ...

  4. 干货-Google支付后台验证操作流程【业务后台-GP后台流程】

    整个开发背景是前端在调用完google play支付流程后,需要后台验证支付结果以及在自己的服务生成订单相关信息. 由此着手对google后台验证的调研,首先官方流程: 点我查看官方流程 整个操作流程 ...

  5. php 企业微信指令回调借款_php处理微信支付回调改变订单支付状态的代码

    本篇文章给大家带来的内容是关于php服务端APP微信支付回调验证签名改变订单支付状态,有一定的参考价值,有需要的朋友可以参考一下,希望对你有所帮助.<?php //处理微信支付回调 $time ...

  6. PHP版本Google广告admob服务端回调验证SSV

    老文章,搬运到这里而已. 因业务需要接入Google的激励广告,涉及Google回调的服务器端验证 (SSV) server side verifiy. Python版本的基于第三方包ecdsa开箱即 ...

  7. PHP判断ip是否在指定IP段内(微信支付回调IP段验证)

    需求: 项目中需要判断发起微信支付回调的IP在不在微信商户出口IP中,以防止私钥泄露别人发起伪装过的假回调造成损失 1获取客户端IP /*** @explain 获取用户IP* @param int ...

  8. Google Pay 应用已经发布成功,调起支付回调失败

    问题描述 Flutter应用在Google Play上架成功,许可测试等配置也都配置完成,但是调起支付的时候,从初始化–>查询商品信息–>调支付都没问题,就是到支付回调的时候Respons ...

  9. PHP微信支付回调接口下单,如何验证微信支付签名 ,处理异步回调(验证的坑)

    在写这之前  看了好多文档,有好多坑在里面,通过多半天的努力终于把验证的问题搞出来了我也不理解微信官网文档写的那么不清晰,一个简单的介绍就能介绍明白,弄一大堆还没写明白,下面直接把我实操的验证贴上,供 ...

最新文章

  1. Keras【Deep Learning With Python】MNIST数据集识别优化
  2. 第二十讲 拉普拉斯变换求解线性ODE
  3. 华兴数控g71外圆循环编程_华兴数控系统代码
  4. CentOS7使用nmcli实现网络日常管理及多网卡bond
  5. NDK编译错误expected specifier-qualifier-list before...
  6. stc单片机c语言 pdf,STC单片机C语言程序设计 第13章 STC单片机C语言指针.pdf
  7. 英雄联盟怎么解除小窗口_英雄联盟手游怎么加好友_英雄联盟手游怎么加好友一起玩_资讯...
  8. Quartus17报错Top-level design entity “dff“ is undefined的解决办法
  9. [第四组]TOUCHBeta版本测试报告及发布说明
  10. 【网络安全】PGP/GPG优质教程汇总
  11. JavaScript高级程序设计(第三版)pdf的下载地址
  12. java dwg转pdf_CAD处理控件Aspose.CAD转换功能演示:使用Java将DWG和DXF文件转换为PDF...
  13. 数字化智慧园区建设方案
  14. Enterprise Architect 类关系对应解析
  15. 三位数除以两位数竖式计算没有余数_三位数除两位数计算题-云簿杜同学
  16. vue项目报错in ./src/app.vue?vuetype=styleindex=0lang=less
  17. 「视频」重磅 | Magic Leap再发Demo,凯文·凯利万字长文揭秘
  18. c语言规定对程序中所用的变量必须,【判断题】C语言程序中要用到的变量必须先定义,然后再使用...
  19. 2022年最新的Gmail用户统计数据
  20. 【20180904】【查漏补缺】量纲分析法—Pi定理(Buckingham定理)

热门文章

  1. git 推送出现 quot;fatal: The remote end hung up unexpectedlyquot; 解决方案
  2. 东亚银行领千万级罚单、“十四五”数字经济发展规划发布、数百万路由器受漏洞影响|网络安全周报
  3. C语言判断10(可修改)以内素数并打印出来
  4. 让程序员崩溃的 60 个瞬间
  5. 确实, 5G与物联网离不开区块链!
  6. MSE 治理中心重磅升级-流量治理、数据库治理、同 AZ 优先
  7. 电子计算机的发展与应用ppt,计算机发展简史ppt
  8. Godsend(博弈)
  9. 杨森翔的生活照片——雪泥鸿爪
  10. CREO学习问题——不显示弱尺寸,无法标注线段长度