123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246 |
- <?php
- require_once dirname ( __FILE__ ).DIRECTORY_SEPARATOR.'./../../AopSdk.php';
- require dirname ( __FILE__ ).DIRECTORY_SEPARATOR.'./../../config.php';
- class AlipayTradeService {
-
- public $gateway_url = "https://openapi.alipay.com/gateway.do";
-
- public $alipay_public_key;
-
- public $private_key;
-
- public $appid;
-
- public $charset = "UTF-8";
- public $token = NULL;
-
-
- public $format = "json";
-
- public $signtype = "RSA";
- function __construct($alipay_config){
- $this->gateway_url = $alipay_config['gatewayUrl'];
- $this->appid = $alipay_config['app_id'];
- $this->private_key = $alipay_config['merchant_private_key'];
- $this->alipay_public_key = $alipay_config['alipay_public_key'];
- $this->charset = $alipay_config['charset'];
- $this->signtype=$alipay_config['sign_type'];
- if(empty($this->appid)||trim($this->appid)==""){
- throw new Exception("appid should not be NULL!");
- }
- if(empty($this->private_key)||trim($this->private_key)==""){
- throw new Exception("private_key should not be NULL!");
- }
- if(empty($this->alipay_public_key)||trim($this->alipay_public_key)==""){
- throw new Exception("alipay_public_key should not be NULL!");
- }
- if(empty($this->charset)||trim($this->charset)==""){
- throw new Exception("charset should not be NULL!");
- }
- if(empty($this->gateway_url)||trim($this->gateway_url)==""){
- throw new Exception("gateway_url should not be NULL!");
- }
- }
- function AlipayWapPayService($alipay_config) {
- $this->__construct($alipay_config);
- }
-
- function wapPay($builder,$return_url,$notify_url) {
-
- $biz_content=$builder->getBizContent();
-
- $this->writeLog($biz_content);
-
- $request = new AlipayTradeWapPayRequest();
-
- $request->setNotifyUrl($notify_url);
- $request->setReturnUrl($return_url);
- $request->setBizContent ( $biz_content );
-
-
- $response = $this->aopclientRequestExecute ($request,true);
-
- return $response;
- }
- function aopclientRequestExecute($request,$ispage=false) {
- $aop = new AopClient ();
- $aop->gatewayUrl = $this->gateway_url;
- $aop->appId = $this->appid;
- $aop->rsaPrivateKey = $this->private_key;
- $aop->alipayrsaPublicKey = $this->alipay_public_key;
- $aop->apiVersion ="1.0";
- $aop->postCharset = $this->charset;
- $aop->format= $this->format;
- $aop->signType=$this->signtype;
-
- $aop->debugInfo=true;
- if($ispage)
- {
- $result = $aop->pageExecute($request,"post");
- echo $result;
- }
- else
- {
- $result = $aop->Execute($request);
- }
-
-
- $this->writeLog("response: ".var_export($result,true));
- return $result;
- }
-
- function Query($builder){
- $biz_content=$builder->getBizContent();
-
- $this->writeLog($biz_content);
- $request = new AlipayTradeQueryRequest();
- $request->setBizContent ( $biz_content );
-
- $response = $this->aopclientRequestExecute ($request);
- $response = $response->alipay_trade_query_response;
- var_dump($response);
- return $response;
- }
-
-
- function Refund($builder){
- $biz_content=$builder->getBizContent();
-
- $this->writeLog($biz_content);
- $request = new AlipayTradeRefundRequest();
- $request->setBizContent ( $biz_content );
-
-
- $response = $this->aopclientRequestExecute ($request);
- $response = $response->alipay_trade_refund_response;
- var_dump($response);
- return $response;
- }
-
- function Close($builder){
- $biz_content=$builder->getBizContent();
-
- $this->writeLog($biz_content);
- $request = new AlipayTradeCloseRequest();
- $request->setBizContent ( $biz_content );
-
-
- $response = $this->aopclientRequestExecute ($request);
- $response = $response->alipay_trade_close_response;
- var_dump($response);
- return $response;
- }
-
-
- function refundQuery($builder){
- $biz_content=$builder->getBizContent();
-
- $this->writeLog($biz_content);
- $request = new AlipayTradeFastpayRefundQueryRequest();
- $request->setBizContent ( $biz_content );
-
-
- $response = $this->aopclientRequestExecute ($request);
- var_dump($response);
- return $response;
- }
-
- function downloadurlQuery($builder){
- $biz_content=$builder->getBizContent();
-
- $this->writeLog($biz_content);
- $request = new alipaydatadataservicebilldownloadurlqueryRequest();
- $request->setBizContent ( $biz_content );
-
-
- $response = $this->aopclientRequestExecute ($request);
- $response = $response->alipay_data_dataservice_bill_downloadurl_query_response;
- var_dump($response);
- return $response;
- }
-
- function check($arr){
- $aop = new AopClient();
- $aop->alipayrsaPublicKey = $this->alipay_public_key;
- $result = $aop->rsaCheckV1($arr, $this->alipay_public_key, $this->signtype);
- return $result;
- }
-
-
- function writeLog($text) {
-
-
- file_put_contents ( dirname ( __FILE__ ).DIRECTORY_SEPARATOR."./../../log.txt", date ( "Y-m-d H:i:s" ) . " " . $text . "\r\n", FILE_APPEND );
- }
-
-
- function create_erweima($content, $size = '200', $lev = 'L', $margin= '0') {
- $content = urlencode($content);
- $image = '<img src="http://chart.apis.google.com/chart?chs='.$size.'x'.$size.'&cht=qr&chld='.$lev.'|'.$margin.'&chl='.$content.'" widht="'.$size.'" height="'.$size.'" />';
- return $image;
- }
- }
- ?>
|