Blogger Information
Blog 142
fans 5
comment 0
visits 130630
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
组织APP支付时的支付订单信息
php开发大牛
Original
693 people have browsed it

<?php

 

require_once (__DIR__.'/alipay-sdk-PHP-20171023143822/AopSdk.php');

 

class Alipay

{

 /**

 * 应用ID

 */

 const APPID = '你的应用ID';

 /**

 *请填写开发者私钥去头去尾去回车,一行字符串

 */

 const RSA_PRIVATE_KEY = '应用对应开发者私钥';

 /**

 *请填写支付宝公钥,一行字符串

 */

 const ALIPAY_RSA_PUBLIC_KEY = '支付宝提供的公钥';

 /**

 * 支付宝服务器主动通知商户服务器里指定的页面

 * @var string

 */

 private $callback = "http://www.test.com/notify/alipay_notify.php";

 

 /**

 *生成APP支付订单信息

 * @param string $orderId 商品订单ID

 * @param string $subject 支付商品的标题

 * @param string $body 支付商品描述

 * @param float $pre_price 商品总支付金额

 * @param int $expire 支付交易时间

 * @return bool|string 返回支付宝签名后订单信息,否则返回false

 */

 public function unifiedorder($orderId, $subject,$body,$pre_price,$expire){

 try{

  $aop = new \AopClient();

  $aop->gatewayUrl = "https://openapi.alipay.com/gateway.do";

  $aop->appId = self::APPID;

  $aop->rsaPrivateKey = self::RSA_PRIVATE_KEY;

  $aop->format = "json";

  $aop->charset = "UTF-8";

  $aop->signType = "RSA2";

  $aop->alipayrsaPublicKey = self::ALIPAY_RSA_PUBLIC_KEY;

  //实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay

  $request = new \AlipayTradeAppPayRequest();

  //SDK已经封装掉了公共参数,这里只需要传入业务参数

  $bizcontent = "{\"body\":\"{$body}\"," //支付商品描述

  . "\"subject\":\"{$subject}\"," //支付商品的标题

  . "\"out_trade_no\":\"{$orderId}\"," //商户网站唯一订单号

  . "\"timeout_express\":\"{$expire}m\"," //该笔订单允许的最晚付款时间,逾期将关闭交易

  . "\"total_amount\":\"{$pre_price}\"," //订单总金额,单位为元,精确到小数点后两位,取值范围[0.01,100000000]

  . "\"product_code\":\"QUICK_MSECURITY_PAY\""

  . "}";

  $request->setNotifyUrl($this->callback);

  $request->setBizContent($bizcontent);

  //这里和普通的接口调用不同,使用的是sdkExecute

  $response = $aop->sdkExecute($request);

  //htmlspecialchars是为了输出到页面时防止被浏览器将关键参数html转义,实际打印到日志以及http传输不会有这个问题

  return htmlspecialchars($response);//就是orderString 可以直接给客户端请求,无需再做处理。

 }catch (\Exception $e){

  return false;

 }

 

 }

}


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post