支付宝接口的使用

#用户私钥
$pri_key = “”;
#用户公钥必要时取消是给支付宝的
// $pub_key = “”
#引入签名
// include ‘./Rsa.php’;
r s a = n e w R S A ( ) ; / / v a r d u m p ( rsa = new RSA(); //var_dump( rsa=newRSA();//vardump(rsa);exit;
// echo $rsa->test();
//公共请求参数
$arr = [
#appid
‘app_id’ => ‘2016091700535066’,
‘method’ => ‘alipay.trade.wap.pay’,
#同步地址
‘return_url’ => ‘http://www.weishop.com/paysuccess’,
#异步地址
‘notify_url’ => ‘http://58.87.109.107/paySuccess.php’,
‘charset’ => ‘utf-8’,
‘sign_type’ => ‘RSA2’,
‘timestamp’ => date(‘Y-m-d H:i:s’),
‘version’ => ‘1.0’,
‘biz_content’ => ‘’,
];
//业务请求参数
$arr_params = [
#订单名称
‘subject’=>‘张孟伟’,
#用户唯一订单号
‘out_trade_no’=> “”,
#价格
‘total_amount’=>’’,
‘product_code’=>‘QUICK_WAP_WAY’
];
a r r [ ′ b i z c o n t e n t ′ ] = j s o n e n c o d e ( arr['biz_content'] = json_encode( arr[bizcontent]=jsonencode(arr_params,JSON_UNESCAPED_UNICODE);
ksort($arr);
s t r = u r l d e c o d e ( h t t p b u i l d q u e r y ( str = urldecode(http_build_query( str=urldecode(httpbuildquery(arr));
$rsa = new Rsa();
$arr[‘sign’] = r s a − > r s a S i g n ( rsa->rsaSign( rsa>rsaSign(str, p r i k e y ) ; h e a d e r ( ′ l o c a t i o n : h t t p s : / / o p e n a p i . a l i p a y d e v . c o m / g a t e w a y . d o ? ′ . h t t p b u i l d q u e r y ( pri_key); header('location:https://openapi.alipaydev.com/gateway.do?' . http_build_query( prikey);header(location:https://openapi.alipaydev.com/gateway.do?.httpbuildquery(arr));

引进的类文件

<?php namespace App\rsa; /** * Created by PhpStorm. * User: lenovo * Date: 2018/9/10 * Time: 22:54 */ class Rsa { /** * RSA签名 * @param $data 待签名数据 * @param $private_key 私钥字符串 * return 签名结果 */ function rsaSign($data, $private_key) { $search = [ "-----BEGIN RSA PRIVATE KEY-----", "-----END RSA PRIVATE KEY-----" ]; $private_key=str_replace($search,"",$private_key); $private_key=$search[0] . PHP_EOL . wordwrap($private_key, 64, "\n", true) . PHP_EOL . $search[1]; $res=openssl_get_privatekey($private_key); if($res) { openssl_sign($data, $sign,$res,OPENSSL_ALGO_SHA256); openssl_free_key($res); }else { exit("私钥格式有误"); } $sign = base64_encode($sign); return $sign; } /** * RSA验签 * @param $data 待签名数据 * @param $public_key 公钥字符串 * @param $sign 要校对的的签名结果 * return 验证结果 */ function rsaCheck($data, $public_key, $sign) { $search = [ "-----BEGIN PUBLIC KEY-----", "-----END PUBLIC KEY-----" ]; $public_key=str_replace($search,"",$public_key); $public_key=$search[0] . PHP_EOL . wordwrap($public_key, 64, "\n", true) . PHP_EOL . $search[1]; $res=openssl_get_publickey($public_key); if($res) { $result = (bool)openssl_verify($data, base64_decode($sign), $res,OPENSSL_ALGO_SHA256); openssl_free_key($res); }else{ exit("公钥格式有误!"); } return $result; } }
  • 0
    点赞
  • 0
    评论
  • 0
    收藏
  • 一键三连
    一键三连
  • 扫一扫,分享海报

©️2021 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、C币套餐、付费专栏及课程。

余额充值