php微信支付之APP支付方法文档格式.docx
- 文档编号:21618891
- 上传时间:2023-01-31
- 格式:DOCX
- 页数:6
- 大小:16.22KB
php微信支付之APP支付方法文档格式.docx
《php微信支付之APP支付方法文档格式.docx》由会员分享,可在线阅读,更多相关《php微信支付之APP支付方法文档格式.docx(6页珍藏版)》请在冰豆网上搜索。
//生成预支付订单提交地址
constPOST_ORDER_URL='
publicfunction__construct()
{
$this->
file=__DIR__.'
/payAccessToken.txt'
;
}
/**
*创建APP支付最终返回参数
*@throws\Exception
*@returnmultitype:
stringNULL
*/
publicfunctioncreateAppPayData()
generateConfig();
$prepayid=$this->
getPrepayid();
try{
$array=[
'
appid'
=>
appid,
appkey'
paySignkey,
noncestr'
getRandomStr(),
package'
Sign=WXPay'
partnerid'
partnerId,
prepayid'
$prepayid,
timestamp'
(string)time(),
];
$array['
sign'
]=$this->
sha1Sign($array);
unset($array['
]);
}catch(\Exception$e){
thrownew\Exception($e->
getMessage());
return$array;
*验证支付成功后的通知参数
*
*@returnboolean
publicfunctionverifyNotify()
$staySignStr=$this->
notify;
unset($staySignStr['
$sign=$this->
signData($staySignStr);
return$this->
notify['
]===$sign;
*魔术方法,给添加支付参数进来
*@paramstring$name
参数名
*@paramstring$value
参数值
publicfunction__set($name,$value)
$name=$value;
*设置accesstoken
*@paramstring$token
publicfunctionsetAccessToken()
if(!
file_exists($this->
file)||!
is_file($this->
file)){
$f=fopen($this->
file,'
a'
);
fclose($f);
$content=file_get_contents($this->
file);
empty($content)){
$info=$content,true);
if(time()-$info['
getTime'
]<
7150){
accessToken=$info['
accessToken'
];
returntrue;
//文件内容为空或accesstoken已失效,重新获取
outputAccessTokenToFile();
*写入accesstoken到文件
protectedfunctionoutputAccessTokenToFile()
wb'
$token=[
getAccessToken(),
time(),
flock($f,LOCK_EX);
fwrite($f,$token));
flock($f,LOCK_UN);
accessToken=$token['
*取accesstoken
*@returnstring
protectedfunctiongetAccessToken()
$url=sprintf(self:
:
ACCESS_TOKEN_URL,$this->
appid,$this->
appSecret);
$result=$this->
getUrl($url),true);
if(isset($result['
errcode'
])){
thrownew\Exception("
getaccesstokenfailed:
{$result['
errmsg'
]}"
return$result['
access_token'
*取预支付会话标识
protectedfunctiongetPrepayid()
$data=$this->
config);
POST_ORDER_URL,$this->
accessToken);
postUrl($url,$data),true);
if(isset($result['
])&
&
$result['
]!
=0){
thrownew\Exception($result['
if(!
isset($result['
])){
thrownew\Exception('
getprepayidfailed,urlrequesterror.'
*组装预支付参数
protectedfunctiongenerateConfig()
config=[
traceid'
traceid,
generatePackage(),
sign_method'
sign_method,
config['
app_signature'
generateSign();
*生成package字段
*生成规则:
*1、生成sign的值signValue
*2、对package参数再次拼接成查询字符串,值需要进行urlencode
*3、将sign=signValue拼接到2生成的字符串后面得到最终的package字符串
*第2步urlencode空格需要编码成%20而不是+
*RFC1738会把空格编码成+
*RFC3986会把空格编码成%20
protectedfunctiongeneratePackage()
package['
signData($this->
package);
returnhttp_build_query($this->
package,'
'
'
PHP_QUERY_RFC3986);
*生成签名
protectedfunctiongenerateSign()
$signArray=[
],
sha1Sign($signArray);
*签名数据
*1、字典排序,拼接成查询字符串格式,不需要urlencode
*2、上一步得到的字符串最后拼接上key=paternerKey
*3、MD5哈希字符串并转换成大写得到sign的值signValue
*@paramarray$data待签名数据
*@returnstring最终签名结果
protectedfunctionsignData($data)
ksort($data);
$str=$this->
arrayToString($data);
$str.="
key={$this->
partnerKey}"
returnstrtoupper($this->
signMd5($str));
*sha1签名
*签名规则
*1、字典排序
*2、拼接查询字符串
*3、sha1运算
*@paramarray$arr
protectedfunctionsha1Sign($arr)
ksort($arr);
returnsha1($this->
arrayToString($arr));
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- php 支付 APP 方法