PHP集成支付宝快速实现充值功能
本文将介绍如何快速通过PHP类库来集成、整合支付宝来实现充值功能。如果你的系统想要扩充积分、账户余额等功能,那么就要选择一个第三方支付系统来充值。 支付宝集成时,需要三大步: 1、通过表单提交信息,系统整合信息,提交信息到支付宝; 2、用户进行支
本文将介绍如何快速通过PHP类库来集成、整合支付宝来实现充值功能。如果你的系统想要扩充积分、账户余额等功能,那么就要选择一个第三方支付系统来充值。
支付宝集成时,需要三大步:
1、通过表单提交信息,系统整合信息,提交信息到支付宝;
2、用户进行支付后,支付宝后台通知系统处理;
3、支付宝后台通知完成后,支付宝前台跳转到系统返回地址;
支付宝PHP类
- PHP 类alipay_notify,主要功能是付款过程中服务器通知处理。
- PHP 类alipay_service,根据支付宝外部服务接口生成支付宝地址。
我把这2个类,集中到一个文件alipay.class.inc中,点击这里查看并下载PHP支付宝类源码。
下面主要主要讲解通过支付宝的PHP类来实现整合。
PHP支付宝集成
第一步,建立提交充值的基本信息:
第二步,验证用户提交的金额正确,通过表单验证后,通过支付宝alipay_service类生成支付宝链接,然后跳转到支付宝链接。
function index() {
$total = intval($_POST['total']);
if (!$total) {
$total = 1;
}
$pay_bank = trim($_POST['pay_bank']);
$account = $_POST['_account'];
$base_path = ‘http://’.$_SERVER['HTTP_HOST'].base_path();
$order_id = date(‘YmdHis’, time()); //时间值作为唯一的订单ID号
$subject = $body = ‘LixiPHP充值’.$total.’元’;
$out_trade_no = date(‘YmdHis’, time()).’-’.$account->student['sid'];
//合作身份者ID,以2088开头的16位纯数字
$partner = ’20887015**9*7**’;
//安全检验码,以数字和字母组成的32位字符
$security_code = ‘gc2qxh4**ab***3jp8*****2ptxewks4′;
//签约支付宝账号或卖家支付宝帐户
$seller_email = ‘seller@alipay.com’;
$_input_charset = "UTF-8";
$sign_type = "MD5"; //签名方式
$transport = ‘https’;//字符编码格式
$parameter = array(
"service" => "create_direct_pay_by_user", //交易类型
"partner" => $partner, //合作商户号
"return_url" => $base_path.’alipay/return’, //同步返回
"notify_url" => $base_path.’alipay/notify’, //异步返回
"_input_charset" => ‘UTF-8′, //字符集,默认为GBK
"subject" => $subject, //商品名称,必填
"body" => $subject, //商品描述,必填
"out_trade_no" => $out_trade_no, //商品外部交易号,必填(保证唯一性)
"price" => $total, //商品单价,必填(价格不能为0)
"payment_type" => "1", //默认为1,不需要修改
"quantity" => "1", //商品数量,必填
"paymethod" => ‘directPay’,
"defaultbank" => $pay_bank,
"logistics_fee" =>’0.00′, //物流配送费用
"logistics_payment" =>’BUYER_PAY’, //物流费用付款方式:SELLER_PAY(卖家支付)、BUYER_PAY(买家支付)、BUYER_PAY_AFTER_RECEIVE(货到付款)
"logistics_type" =>’EXPRESS’, //物流配送方式:POST(平邮)、EMS(EMS)、EXPRESS(其他快递)
//"receive _mobile" => ”, //收货人手机
"show_url" => $base_path, //商品相关网站
"seller_email" => $seller_email, //卖家邮箱,必填
);
require("../libraries/payment/alipay.class.inc");
$alipay = new alipay_service($parameter, $security_code, $sign_type);
$link = $alipay->create_url();
header("Location: ".$link);
}
用户跳转到支付宝支付界面后,默认的支付银行是在提交表单前选择的网上银行,选择支付宝的话就是使用支付宝余额支付。然后就是等待用户支付了。用户完成支付后,请会发生下面的几个步骤,当然如果用户放弃支付的话,就没有后面的处理了。
(...)
Read the rest of PHP集成支付宝快速实现充值功能 (294 words)
© lixiphp for LixiPHP, 2013. | Permalink | One comment |
Add to del.icio.us
Post tags: alipay, PHP, zhifubao, 支付宝, 整合支付接口, 集成支付接口
Feed enhanced by Better Feed from Ozh

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



PHP 8.4 brings several new features, security improvements, and performance improvements with healthy amounts of feature deprecations and removals. This guide explains how to install PHP 8.4 or upgrade to PHP 8.4 on Ubuntu, Debian, or their derivati

Visual Studio Code, also known as VS Code, is a free source code editor — or integrated development environment (IDE) — available for all major operating systems. With a large collection of extensions for many programming languages, VS Code can be c

If you are an experienced PHP developer, you might have the feeling that you’ve been there and done that already.You have developed a significant number of applications, debugged millions of lines of code, and tweaked a bunch of scripts to achieve op

This tutorial demonstrates how to efficiently process XML documents using PHP. XML (eXtensible Markup Language) is a versatile text-based markup language designed for both human readability and machine parsing. It's commonly used for data storage an

JWT is an open standard based on JSON, used to securely transmit information between parties, mainly for identity authentication and information exchange. 1. JWT consists of three parts: Header, Payload and Signature. 2. The working principle of JWT includes three steps: generating JWT, verifying JWT and parsing Payload. 3. When using JWT for authentication in PHP, JWT can be generated and verified, and user role and permission information can be included in advanced usage. 4. Common errors include signature verification failure, token expiration, and payload oversized. Debugging skills include using debugging tools and logging. 5. Performance optimization and best practices include using appropriate signature algorithms, setting validity periods reasonably,

A string is a sequence of characters, including letters, numbers, and symbols. This tutorial will learn how to calculate the number of vowels in a given string in PHP using different methods. The vowels in English are a, e, i, o, u, and they can be uppercase or lowercase. What is a vowel? Vowels are alphabetic characters that represent a specific pronunciation. There are five vowels in English, including uppercase and lowercase: a, e, i, o, u Example 1 Input: String = "Tutorialspoint" Output: 6 explain The vowels in the string "Tutorialspoint" are u, o, i, a, o, i. There are 6 yuan in total

Static binding (static::) implements late static binding (LSB) in PHP, allowing calling classes to be referenced in static contexts rather than defining classes. 1) The parsing process is performed at runtime, 2) Look up the call class in the inheritance relationship, 3) It may bring performance overhead.

What are the magic methods of PHP? PHP's magic methods include: 1.\_\_construct, used to initialize objects; 2.\_\_destruct, used to clean up resources; 3.\_\_call, handle non-existent method calls; 4.\_\_get, implement dynamic attribute access; 5.\_\_set, implement dynamic attribute settings. These methods are automatically called in certain situations, improving code flexibility and efficiency.
