关于网站支付

支付

使用Yansongda\Pay\Pay
https://github.com/yansongda/pay
composer require yansongda/pay -vvv
生成密钥

商户私钥>应用公钥>支付宝公钥

openssl
# 生成商户私钥2048位或者1024位:private_key
OpenSSL> genrsa -out rsa_private_key.pem 2048
# Java开发者需要将私钥转换成PKCS8格式
OpenSSL> pkcs8 -topk8 -inform PEM -in rsa_private_key.pem -outform PEM -nocrypt -out rsa_private_key_pkcs8.pem
# 生成应用公钥:rsa_public_key
OpenSSL> rsa -in rsa_private_key.pem -pubout -out rsa_public_key.pem
# 到支付宝填写应用公钥获得支付宝公钥:ali_public_key

notify格式

{
	"gmt_create": "2018-10-19 15:32:27",
	"charset": "GBK",
	"seller_email": "[email protected]",
	"subject": "商城中心 - 会员充值",
	"sign": "NXycpuWEP9SpH/cDq/xayMDas6PKAfieCuxPyzo455o814v0y7+k0Ep+j66g65oC9S1HLHvphUZzZEN5rZCOZcPcJ9D8Q0EkTd1RiZDitGqAzpWnyoEKhisMd2gn83I3ghBVbOk3TcPGyGpLB/j5/zigN56ZLwTMOlG+4B86rXTG0Rf/L3rMnNdEzUbrknRSI5486+6KIQJZN9+CFjollzoDsrOF+BLmhMW98Ay4z/oiZRSE7Q7k6R5LkbCG/IMx6eYH8Jc0w3Abbqjdt+UHVe1eG+om52v+X6HywQBmIybxt/N47y3QOk1YQRFbPN65KSJlcO2QnKtByN6cW6ToNQ==",
	"buyer_id": "",
	"invoice_amount": "0.01",
	"notify_id": "",
	"fund_bill_list": "[{\"amount\":\"0.01\",\"fundChannel\":\"PCREDIT\"}]",
	"notify_type": "trade_status_sync",
	"trade_status": "TRADE_SUCCESS",
	"receipt_amount": "0.01",
	"buyer_pay_amount": "0.01",
	"app_id": "",
	"sign_type": "RSA2",
	"seller_id": "2088411957695896",
	"gmt_payment": "2018-10-19 15:32:28",
	"notify_time": "2018-10-19 16:56:04",
	"version": "1.0",
	"out_trade_no": "2018101601599",
	"total_amount": "0.01",
	"trade_no": "2018101922001467891006772698",
	"auth_app_id": "2018062160408670",
	"buyer_logon_id": "j.c***@foxmail.com",
	"point_amount": "0.00"
}

支付宝wap支付

<?php
namespace app\index\controller;

use think\Controller;
use think\Db;
use Yansongda\Pay\Pay;

class Alipay extends Controller
{
    protected $config = [
        'app_id'         => '2018071060522789',
        'notify_url'     => 'http://shop2.xxx.club/index/Alipay/notify',
        'return_url'     => 'http://shop2.xxx.club/index/Alipay/return',
        // 支付宝公钥,不是应用公钥
        'ali_public_key' => '',
        // 商户私钥,加密方式: **RSA2**
        'private_key'    => '',
        'log'            => [ // optional
            'file'     => ROOT_PATH . 'runtime/alipay.log',
            'level'    => 'debug', // 建议生产环境等级调整为 info,开发环境为 debug
            'type'     => 'single', // optional, 可选 daily.
            'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
        ],
        'http'           => [ // optional
            'timeout'         => 5.0,
            'connect_timeout' => 5.0,
            // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
        ],
        // 'mode'           => 'dev', // optional,设置此参数,将进入沙箱模式
    ];

    public function do_order($order_id)
    {
        $orderinfo = Db::table('nt_order')->where('id', $order_id)->find();
        $order     = [
            'out_trade_no' => $orderinfo['order_sn'],
            'total_amount' => $orderinfo['price'],
            'subject'      => '商城中心 - 会员充值',
        ];
        $alipay = Pay::alipay($this->config)->wap($order);
        halt($alipay->send());
        return $alipay->send(); // laravel 框架中请直接 `return $alipay`
    }

    function return () {
        // $data = Pay::alipay($this->config)->verify(); // 是的,验签就这么简单!
        $this->success('请稍候参看支付状态', '/index/index/index');
    }

    public function notify()
    {
        try {
            $alipay = Pay::alipay($this->config);
            $data   = $alipay->verify();
            if ($data) {
                if ($data->trade_status == 'TRADE_SUCCESS' || $data->trade_status == 'TRADE_FINISHED') {
                    $order_sn    = $data->out_trade_no;
                    $order_price = $data->total_amount;
                    $orderinfo   = Db::table('nt_order')->where('order_sn', $order_sn)->find();
                    if ($orderinfo['is_pay'] == 1) {
                        return $alipay->success()->send();
                    }
                    if ($order_price != $orderinfo['price']) {
                        exit('fail');
                    }
                    $is_update = Db::table('nt_order')->where('order_sn', $order_sn)->update(['is_pay' => 1, 'pay_time' => date('Y-m-d H:i:s')]);
                    if ($is_update) {
                        return $alipay->success()->send();
                    }
                }
            } else {
                exit('fail');
            }
        } catch (Exception $e) {
            exit('fail');
        }
    }
}

猜你喜欢

转载自blog.csdn.net/HD2killers/article/details/83183732
今日推荐