VB.net 2010 视频教程 VB.net 2010 视频教程 python基础视频教程
SQL Server 2008 视频教程 c#入门经典教程 Visual Basic从门到精通视频教程
当前位置:
首页 > PHP >
  • IOS订阅优惠-PHP生成ECDSA算法签名

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
use Ramsey\Uuid\Uuid;
 
class ItunesSignatureGenerator {
    private $appBundleID 'www.u17.com';
 
    private $keyIdentifier 'ZZZZZZZ';
 
    private $itunesPrivateKeyPath = '/path/to/the/file.p8;
 
    /**
     * @see https://developer.apple.com/documentation/storekit/in-app_purchase/generating_a_signature_for_subscription_offers
     *
     * @param $productIdentifier
     * @param $offerIdentifier
     *
     * @return Signature
     */
    public function generateSubscriptionOfferSignature($productIdentifier$offerIdentifier)
    {
        $nonce strtolower(Uuid::uuid1()->toString());
        $timestamp = time() * 1000;
        $applicationUsername 'username';
 
        $message = implode(
            "\u{2063}",
            [
                $this->appBundleID,
                $this->keyIdentifier,
                $productIdentifier,
                $offerIdentifier,
                $applicationUsername,
                $nonce,
                $timestamp
            ]
        );
 
        $message $this->sign($message);
 
        return new Signature(
            base64_encode($message),
            $nonce,
            $timestamp,
            $this->keyIdentifier
        );
    }
 
    private function sign($data)
    {
        $signature '';
 
        openssl_sign(
            $data,
            $signature,
            openssl_get_privatekey('file://' $this->itunesPrivateKeyPath),
            OPENSSL_ALGO_SHA256
        );
 
        return $signature;
    }
}