Google Play Developer API를 사용하여 안드로이드의 in-app billing 영수증 확인 (메모)

4186 단어 AndroidIn-appBilling

Google Play Developer API를 사용하여 영수증 확인


※ 완전한 개인 메모여서 내용이 새롭지 않고, 원래 쓸 때 가장 좋지 않을 수도 있습니다.

전제 조건


· 인앱빌링을 통해 소비형 물품 판매 시 영수증 정보가 정확한지 확인
• 영수증 정보 취득 등이 이미 이루어졌다

차리다

  • 계약 계정으로 개발자 콘솔에 로그인, 개발자 계정->API 액세스
  • Google Play Android Developer에 대한 링크
  • OAuth 클라이언트 생성
  • Google Developers Console을 통해 생성된 클라이언트의 클라이언트 ID, 기밀을 확인
  • OAuth 인증


    브라우저를 통해 다음 URL에 액세스
    https://accounts.google.com/o/oauth2/auth?scope=https://www.googleapis.com/auth/androidpublisher&response_type=code&access_type=offline&redirect_uri=http://localhost&client_id=<準備.4で確認したクライアントID>
    
    Google 계정 링크 화면 허용
    http://localhost/?code=4/AACyzBvuCgBZQKv8VKPvCQl5Szt6U47GClAPLk0qTuItTUmUoFKJWqUfSyJN2bTCqLDXXXXXXXXXXXXXXXXXXXX#
    URL에 연결되어 있으므로 code=의 섹션

    액세스 토큰 획득


    POST 요청을 위해 Curl로 실행
    
    $ curl -v -X POST 'https://accounts.google.com/o/oauth2/token' -d 'grant_type=authorization_code&code=<上記OAuth認証で取得したCode#まで>&client_id=<準備.4で確認したクライアントID>&client_secret=準備.4で確認したクライアントシークレット>&redirect_uri=http://localhost'
    

    상술한 결과를 되돌려주기 때문에accesstoken/refresh_Token 확인

    영수증 검증


    드디어 주제
    영수증 정보에서
    ・package Name
    ・ProductId
    ・purchaseToken
    미리 확인한다
    우선 수동 검증...
    $ curl -v 'https://www.googleapis.com/androidpublisher/v3/applications/<packageName>/purchases/products/<productId>/tokens/<purchaseToken>?access_token=<アクセストークン取得で取得したaccess_token>'
    

    위와 같은 결과가 나오면 OK입니다.
    결과 상세 정보https://developers.google.com/android-publisher/api-ref/purchases/products#resource
    요컨대
    consumptionState:1
    개발자 Paylload: 결제 시 보낸 유효 하중과 일치하는지 여부
    purchaseState:0
    주변 상황을 확인하고 검증하는 게 좋을 것 같아요.
    여기까지 확인한 후 동일한 처리를 실시해야 한다
    문제는access입니다.Token은 수령 시작 1시간 이내에 만료됩니다.

    access_Token 업데이트

    $ curl -v -X POST 'https://accounts.google.com/o/oauth2/token' -d 'grant_type=refresh_token&client_id=<クライアントID>&client_secret=<クライアントシークレット>&refresh_token=<アクセストークン取得時に確認したrefresh_token>'
    

    새로운 access토큰을 획득할 수 있습니다.

    프로세스 구현


    상술한 내용에 근거하여
  • 영수증 정보 획득
  • access_token의 업데이트
  • 영수증 검증
  • 프로젝트 수여
  • 이런 절차는 설치하기에 매우 좋은 것 같다.

    참고 자료


    https://groups.google.com/forum/#!topic/android-group-japan/jaaIGAl2lPE
    http://d.hatena.ne.jp/fkm/20130504
    https://developers.google.com/android-publisher/api-ref/purchases/products

    좋은 웹페이지 즐겨찾기