Skip to content

Instantly share code, notes, and snippets.

@ys4kw
Last active December 20, 2015 04:09
Show Gist options
  • Save ys4kw/6069138 to your computer and use it in GitHub Desktop.
Save ys4kw/6069138 to your computer and use it in GitHub Desktop.
RubyでのAndroidの課金処理
def in_app_purchase signature, receipt_data, base64_encoded_public_key
  public_key = OpenSSL::PKey::RSA.new(base64_encoded_public_key)
  if public_key.verify(OpenSSL::Digest::SHA1.new, Base64.decode64(signature), receipt_data)
    # Success
  else
    # Failure
  end
end

signature、receipt_dataは、課金成功時にGoogle Playから受け取る
(receipt_dataはjson)

base64_encoded_public_keyは、Google Playから取得する公開キーをpemにしたもの File.read('public.pem')で渡せばOK

public.pem作成

  1. public keyをpublicファイルに入力
  2. base64 -d public > public.der (osxのbase64コマンドは base64 -Dを使う)
  3. openssl rsa -inform DER -outform PEM -pubin -in public.der -out public.pem
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment