林一峰
7 years ago
10 changed files with 1437 additions and 6 deletions
-
1.env.example
-
5app/Http/Controllers/Home/IndexController.php
-
3config/app.php
-
4config/custom.php
-
118resources/org/alipay_app/AlipayTradeAppPayRequest.php
-
1193resources/org/alipay_app/AopClient.php
-
73resources/org/alipay_app/AopEncrypt.php
-
43resources/org/alipay_app/demo.php
-
0resources/org/alipay_app/说明.txt
-
3说明.txt
@ -0,0 +1,118 @@ |
|||
<?php |
|||
/** |
|||
* ALIPAY API: alipay.trade.app.pay request |
|||
* |
|||
* @author auto create |
|||
* @since 1.0, 2017-06-19 11:12:46 |
|||
*/ |
|||
class AlipayTradeAppPayRequest |
|||
{ |
|||
/** |
|||
* app支付接口2.0 |
|||
**/ |
|||
private $bizContent; |
|||
|
|||
private $apiParas = array(); |
|||
private $terminalType; |
|||
private $terminalInfo; |
|||
private $prodCode; |
|||
private $apiVersion="1.0"; |
|||
private $notifyUrl; |
|||
private $returnUrl; |
|||
private $needEncrypt=false; |
|||
|
|||
|
|||
public function setBizContent($bizContent) |
|||
{ |
|||
$this->bizContent = $bizContent; |
|||
$this->apiParas["biz_content"] = $bizContent; |
|||
} |
|||
|
|||
public function getBizContent() |
|||
{ |
|||
return $this->bizContent; |
|||
} |
|||
|
|||
public function getApiMethodName() |
|||
{ |
|||
return "alipay.trade.app.pay"; |
|||
} |
|||
|
|||
public function setNotifyUrl($notifyUrl) |
|||
{ |
|||
$this->notifyUrl=$notifyUrl; |
|||
} |
|||
|
|||
public function getNotifyUrl() |
|||
{ |
|||
return $this->notifyUrl; |
|||
} |
|||
|
|||
public function setReturnUrl($returnUrl) |
|||
{ |
|||
$this->returnUrl=$returnUrl; |
|||
} |
|||
|
|||
public function getReturnUrl() |
|||
{ |
|||
return $this->returnUrl; |
|||
} |
|||
|
|||
public function getApiParas() |
|||
{ |
|||
return $this->apiParas; |
|||
} |
|||
|
|||
public function getTerminalType() |
|||
{ |
|||
return $this->terminalType; |
|||
} |
|||
|
|||
public function setTerminalType($terminalType) |
|||
{ |
|||
$this->terminalType = $terminalType; |
|||
} |
|||
|
|||
public function getTerminalInfo() |
|||
{ |
|||
return $this->terminalInfo; |
|||
} |
|||
|
|||
public function setTerminalInfo($terminalInfo) |
|||
{ |
|||
$this->terminalInfo = $terminalInfo; |
|||
} |
|||
|
|||
public function getProdCode() |
|||
{ |
|||
return $this->prodCode; |
|||
} |
|||
|
|||
public function setProdCode($prodCode) |
|||
{ |
|||
$this->prodCode = $prodCode; |
|||
} |
|||
|
|||
public function setApiVersion($apiVersion) |
|||
{ |
|||
$this->apiVersion=$apiVersion; |
|||
} |
|||
|
|||
public function getApiVersion() |
|||
{ |
|||
return $this->apiVersion; |
|||
} |
|||
|
|||
public function setNeedEncrypt($needEncrypt) |
|||
{ |
|||
|
|||
$this->needEncrypt=$needEncrypt; |
|||
|
|||
} |
|||
|
|||
public function getNeedEncrypt() |
|||
{ |
|||
return $this->needEncrypt; |
|||
} |
|||
|
|||
} |
1193
resources/org/alipay_app/AopClient.php
File diff suppressed because it is too large
View File
File diff suppressed because it is too large
View File
@ -0,0 +1,73 @@ |
|||
<?php |
|||
/** |
|||
* 加密工具类 |
|||
* |
|||
* User: jiehua |
|||
* Date: 16/3/30 |
|||
* Time: 下午3:25 |
|||
*/ |
|||
|
|||
/** |
|||
* 加密方法 |
|||
* 方法名本来是encrypt,与laravel冲突改成encrypt_laravel,by FLi |
|||
* @param string $str |
|||
* @return string |
|||
*/ |
|||
function encrypt_laravel($str,$screct_key){ |
|||
//AES, 128 模式加密数据 CBC
|
|||
$screct_key = base64_decode($screct_key); |
|||
$str = trim($str); |
|||
$str = addPKCS7Padding($str); |
|||
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC),1); |
|||
$encrypt_str = mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $screct_key, $str, MCRYPT_MODE_CBC); |
|||
return base64_encode($encrypt_str); |
|||
} |
|||
|
|||
/** |
|||
* 解密方法 |
|||
* 方法名本来是decrypt,与laravel冲突改成decrypt_laravel,by FLi |
|||
* @param string $str |
|||
* @return string |
|||
*/ |
|||
function decrypt_laravel($str,$screct_key){ |
|||
//AES, 128 模式加密数据 CBC
|
|||
$str = base64_decode($str); |
|||
$screct_key = base64_decode($screct_key); |
|||
$iv = mcrypt_create_iv(mcrypt_get_iv_size(MCRYPT_RIJNDAEL_128,MCRYPT_MODE_CBC),1); |
|||
$encrypt_str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $screct_key, $str, MCRYPT_MODE_CBC); |
|||
$encrypt_str = trim($encrypt_str); |
|||
|
|||
$encrypt_str = stripPKSC7Padding($encrypt_str); |
|||
return $encrypt_str; |
|||
|
|||
} |
|||
|
|||
/** |
|||
* 填充算法 |
|||
* @param string $source |
|||
* @return string |
|||
*/ |
|||
function addPKCS7Padding($source){ |
|||
$source = trim($source); |
|||
$block = mcrypt_get_block_size(MCRYPT_RIJNDAEL_128, MCRYPT_MODE_CBC); |
|||
|
|||
$pad = $block - (strlen($source) % $block); |
|||
if ($pad <= $block) { |
|||
$char = chr($pad); |
|||
$source .= str_repeat($char, $pad); |
|||
} |
|||
return $source; |
|||
} |
|||
/** |
|||
* 移去填充算法 |
|||
* @param string $source |
|||
* @return string |
|||
*/ |
|||
function stripPKSC7Padding($source){ |
|||
$source = trim($source); |
|||
$char = substr($source, -1); |
|||
$num = ord($char); |
|||
if($num==62)return $source; |
|||
$source = substr($source,0,-$num); |
|||
return $source; |
|||
} |
@ -0,0 +1,43 @@ |
|||
<?php |
|||
//PHP服务端SDK生成APP支付订单信息示例
|
|||
public function AlipayTradeAppPayRequest() |
|||
{ |
|||
require_once './AopClient.php'; |
|||
require_once './AlipayTradeAppPayRequest.php'; |
|||
|
|||
$aop = new \AopClient; |
|||
$aop->gatewayUrl = "https://openapi.alipay.com/gateway.do"; |
|||
$aop->appId = "2017070707673008"; |
|||
$aop->rsaPrivateKey = '1fengMIIEpAIBAAKCAQEA5Eccv1+NjMMEMYC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IoqebXCqUXpaqjyzpO3sH260PpNMnZyXlpCO3/Zw+vfvLfqrbGWlsv/11p1mCXtQQvt+lgf6SHZBtU7AbcHu3Ta8h1RcGA/sd09xPN0bXpglQBcoYysx+PVqhrDN+uifye2M/j2hzB5oUCgYBns13UNAJr19kWWcwz0PAQSpGezDMAlabCmW8ZWWR6M3GNOO/R0f/9dT8EKzK0FbrS46pgggZ1KwMbf3xM+TJStHX3XcbYkvCz0b68sLCiBSEP64/cVO9Ykn7u7Yium1jzvqZ4b4X90rkL0mdSt8dKnHs3GH64WBqmzzk+hKOt4QKBgQCwAPwnlLiZmtORdja3rNFrTTXvjua8HVTemMdp2rUuSFB2FXS3suRhqkH2ilMRvbdiP/GlaCOyOTMSOVis88KZKie5Dy26TUgWUMsvG/7d21meRP6SCqpFhw5tkNkTzX+7ul5Si7iabmMtdlhw1OiD7yv4bo3Sw4YTWMa4s4D2ag=='; //请填写开发者私钥去头去尾去回车,一行字符串
|
|||
$aop->format = "json"; |
|||
$aop->charset = "UTF-8"; |
|||
$aop->signType = "RSA2"; |
|||
$aop->alipayrsaPublicKey = '1fengMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmLo5catqqLXWcf+LhRs/WDziyCAB+HPb/+xls2BAtNtvfLHCM9xej5VGTzX7mw6e5/Et3yVAhFnnTZ9U9RWq1m3MiEv19n17/yIbGMXpxSSujYnL0drFBY6Z4f19tzfqWQPETpEf1atFSHbcJQfpaslyr9W2NmS5dbWIe+sJVmZjRN5cYEhFY7U0JHqIPr653XSDzsQ152rHZIb0wJmEVfkr0yyOZl1ja0sx+Gv3/BcHDK1brK94mi9I6J78dDXQS6WSQY7mup9l74Z78FLHf22LtS9GvpkzlL5zAKh0LzTVsgGlyJNMnh0/aRYK4p4IKiSAvQRhLXjfbWLc9XFAzQIDAQAB'; //请填写支付宝公钥,一行字符串
|
|||
//实例化具体API对应的request类,类名称和接口名称对应,当前调用接口名称:alipay.trade.app.pay
|
|||
$request = new \AlipayTradeAppPayRequest(); |
|||
//SDK已经封装掉了公共参数,这里只需要传入业务参数
|
|||
$bizcontent = "{\"body\":\"我是测试数据\"," |
|||
. "\"subject\": \"App支付测试\"," |
|||
. "\"out_trade_no\": \"20170125test01\"," |
|||
. "\"timeout_express\": \"30m\"," |
|||
. "\"total_amount\": \"0.01\"," |
|||
. "\"product_code\":\"QUICK_MSECURITY_PAY\"" |
|||
. "}"; |
|||
$request->setNotifyUrl("http://59.110.220.223:8087/receive_notify"); //商户外网可以访问的异步地址,回调地址
|
|||
$request->setBizContent($bizcontent); |
|||
//这里和普通的接口调用不同,使用的是sdkExecute
|
|||
$response = $aop->sdkExecute($request); |
|||
//htmlspecialchars是为了输出到页面时防止被浏览器将关键参数html转义,实际打印到日志以及http传输不会有这个问题
|
|||
//echo htmlspecialchars($response);//就是orderString 可以直接给客户端请求,无需再做处理。
|
|||
echo $response; |
|||
} |
|||
|
|||
//PHP服务端验证异步通知信息参数示例
|
|||
public function AlipayTradeAppPayNotify() |
|||
{ |
|||
require_once './AopClient.php'; |
|||
|
|||
$aop = new \AopClient; |
|||
$aop->alipayrsaPublicKey = ''; //请填写支付宝公钥,一行字符串
|
|||
$flag = $aop->rsaCheckV1($_POST, NULL, "RSA2"); //RSA2与上面一致
|
|||
} |
Write
Preview
Loading…
Cancel
Save
Reference in new issue