• PHP服务端如何进行苹果登录的验证


    一、材料准备

    1、P8文件:苹果后台生成证书那里的key那里生成,这个文件只可以下载一次,保存好

    2、生成JWT token 的脚本

    二、脚本siwa.rb

    1. #!/usr/bin/env ruby
    2. require 'jwt'
    3. require 'openssl'
    4. require 'optparse'
    5. options = {}
    6. OptionParser.new do |opts|
    7. opts.banner = "Usage: siwa.rb [options]"
    8. opts.on("-k", "--key PATH", "Path to the AuthKey file") do |v|
    9. options[:key] = v
    10. end
    11. opts.on("-t", "--team-id TEAM_ID", "Your Apple Team ID") do |v|
    12. options[:team_id] = v
    13. end
    14. opts.on("-b", "--bundle-id BUNDLE_ID", "Your App's Bundle ID") do |v|
    15. options[:bundle_id] = v
    16. end
    17. opts.on("-h", "--help", "Prints this help") do
    18. puts opts
    19. exit
    20. end
    21. end.parse!
    22. if options[:key].nil? || options[:team_id].nil? || options[:bundle_id].nil?
    23. puts OptionParser.new.help
    24. exit
    25. end
    26. pem_content = File.read options[:key]
    27. ecdsa_key = OpenSSL::PKey::EC.new pem_content
    28. headers = {
    29. 'kid' => options[:team_id],
    30. }
    31. claims = {
    32. 'iss' => options[:team_id],
    33. 'iat' => Time.now.to_i,
    34. 'exp' => Time.now.to_i + 86400*180,
    35. 'aud' => 'https://appleid.apple.com',
    36. 'sub' => options[:bundle_id],
    37. }
    38. token = JWT.encode claims, ecdsa_key, 'ES256', headers
    39. puts token

    三、运行生成token

    1、把脚本放在桌面,命令行执行:chmod +x /Users/say/Desktop/siwa.rb

    2、cd到桌面,运行:./siwa.rb -h

    如果报错:

    /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require': cannot load such file -- jwt (LoadError)

    from /System/Library/Frameworks/Ruby.framework/Versions/2.6/usr/lib/ruby/2.6.0/rubygems/core_ext/kernel_require.rb:54:in `require'

    from ./siwa.rb:3:in `

    '

    说明电脑上没有JWT

    3、安装JWT:sudo gem install jwt

    4、执行:./siwa.rb -h

    终端会输出:

    Usage: siwa.rb [options]

        -k, --key PATH                   Path to the AuthKey file

        -t, --team-id TEAM_ID            Your Apple Team ID

        -b, --bundle-id BUNDLE_ID        Your App's Bundle ID

        -h, --help                       Prints this help

    5、运行:./siwa.rb -k /Users/5T3.p8 -t 684MCOO9T3 -b com.kcys.sx

    就会生成JWT 字符串

  • 相关阅读:
    mybatis 单框架实现数据库查询
    Java进阶学习路线图
    基于深度混合核极限学习机的多变量输入时间序列预测
    极值点偏移练习1
    VoLTE端到端业务详解 | 移动性管理类
    Spring 中不得不了解的姿势
    RTP相关
    x86架构上构建arm64架构的docker镜像
    C# OpenCvSharp 颜色反转
    跟艾文学编程《Python基础》(2)Python 容器
  • 原文地址:https://blog.csdn.net/qq_37203361/article/details/136331480