IOS订阅优惠-PHP生成ECDSA算法签名
2019-07-23 08:41:16来源:博客园 阅读 ()
<?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;
}
}
一些注意事项 openssl是可以直接进行ECDSA签名的
1、$nonce 必须为小写,并且每次购买时的nonce不能重复否则会报签名错误无法购买 code -12
2、$time 是毫秒time*1000
3、\u2063 的字符格式需要注意 php里面可以用户"\u{2063}" 来表示,但是有的一些环境不支持这样的写法 所以还可以使用另外一种 json_decode('"\u2036"') 来转一下格式
原文链接:https://www.cnblogs.com/stephenChang/p/11097635.html
如有疑问请与原作者联系
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
上一篇:php实现命令行里输出带颜色文字
下一篇:PHP中的session
- 【淘宝客】根据淘客联盟精选清单(淘宝天猫内部优惠券)搜索 2018-06-22
- 【淘宝客】根据淘客联盟精选清单(淘宝天猫内部优惠券)随机 2018-06-22
- 【淘宝客】根据淘客联盟精选清单(淘宝天猫内部优惠券)搜索 2018-06-22
- php获取ios或android通过文件头(header)传过来的坐标,通过 2018-06-22
- Paypal如何实现循环扣款(订阅)? 2018-06-22
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
