├── demo ├── wechat.php ├── cer │ └── alipay.cacert.pem ├── wechat.html ├── wechat.refund.php ├── alipay.redirect.php ├── baifu.redirect.php ├── info.php ├── config.php ├── alipay.notify.php ├── wechat.notify.php ├── wechat.redirect.php ├── index.php ├── js │ └── json_to_table.js ├── alipay.redirect.php.html └── wechat.redirect.php.html ├── README.md ├── .gitignore ├── src └── Omnipay │ ├── Wechat │ ├── Sdk │ │ ├── Notify.php │ │ ├── SDKRuntimeException.php │ │ ├── NativeCall.php │ │ ├── OrderQuery.php │ │ ├── ShortUrl.php │ │ ├── DownloadBill.php │ │ ├── WxpayServer.php │ │ ├── NativeLink.php │ │ ├── RefundQuery.php │ │ ├── WxpayClient.php │ │ ├── Refund.php │ │ ├── UnifiedOrder.php │ │ ├── JsApi.php │ │ └── CommonUtil.php │ └── Message │ │ ├── BaseAbstractResponse.php │ │ ├── WechatPrePurchaseResponse.php │ │ ├── WechatCompletePurchaseResponse.php │ │ ├── WechatRefundResponse.php │ │ ├── BaseAbstractRequest.php │ │ ├── WechatPurchaseRequest.php │ │ ├── WechatPrePurchaseRequest.php │ │ ├── WechatRefundRequest.php │ │ ├── WechatPurchaseResponse.php │ │ └── WechatCompletePurchaseRequest.php │ ├── Alipay │ ├── Message │ │ ├── ExpressCompleteRefundResponse.php │ │ ├── ExpressRefundResponse.php │ │ ├── MobileExpressPurchaseResponse.php │ │ ├── PurchaseResponse.php │ │ ├── WapExpressPurchaseResponse.php │ │ ├── WapExpressAuthorizeResponse.php │ │ ├── ExpressCompletePurchaseResponse.php │ │ ├── ExpressCompleteRefundRequest.php │ │ ├── ExpressRefundRequest.php │ │ ├── BaseAbstractRequest.php │ │ ├── WapExpressPurchaseRequest.php │ │ ├── ExpressPurchaseRequest.php │ │ ├── BasePurchaseRequest.php │ │ ├── SecuredPurchaseRequest.php │ │ ├── WapExpressAuthorizeRequest.php │ │ └── MobileExpressPurchaseRequest.php │ ├── DualGateway.php │ ├── MobileExpressGateway.php │ ├── BankGateway.php │ ├── ExpressGateway.php │ ├── SecuredGateway.php │ ├── WapExpressGateway.php │ └── BaseAbstractGateway.php │ ├── Common │ └── Message │ │ └── CompletePurchaseResponseInterface.php │ ├── Netpay │ ├── Message │ │ ├── NetpayCompletePurchaseResponse.php │ │ ├── NetpayCompletePurchaseRequest.php │ │ ├── NetpayPurchaseResponse.php │ │ ├── BaseAbstractRequest.php │ │ └── NetpayPurchaseRequest.php │ └── ExpressGateway.php │ ├── Baifu │ ├── Message │ │ ├── ExpressCompletePurchaseResponse.php │ │ ├── ExpressPurchaseResponse.php │ │ ├── ExpressPurchaseRequest.php │ │ └── ExpressCompletePurchaseRequest.php │ └── ExpressGateway.php │ ├── Utils │ └── Utils.php │ └── Cmpay │ ├── Message │ ├── ExpressPurchaseResponse.php │ └── ExpressPurchaseRequest.php │ ├── ExpressGateway.php │ └── Utils.php ├── composer.json ├── HOWTO └── HOWTO.html /demo/wechat.php: -------------------------------------------------------------------------------- 1 | 4 | * Date: 15/1/19 5 | * Time: 下午5:23 6 | */ 7 | 8 | namespace Omnipay\Alipay\Message; 9 | 10 | 11 | class ExpressCompleteRefundResponse extends ExpressCompletePurchaseResponse { 12 | 13 | 14 | 15 | } -------------------------------------------------------------------------------- /demo/wechat.html: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 |付款中...
9 | 10 | 11 | -------------------------------------------------------------------------------- /src/Omnipay/Wechat/Message/BaseAbstractResponse.php: -------------------------------------------------------------------------------- 1 | 9 | **/ 10 | abstract class BaseAbstractResponse extends AbstractResponse { 11 | 12 | 13 | 14 | } -------------------------------------------------------------------------------- /src/Omnipay/Wechat/Sdk/SDKRuntimeException.php: -------------------------------------------------------------------------------- 1 | 8 | **/ 9 | class SDKRuntimeException extends \Exception { 10 | public function errorMessage() 11 | { 12 | return $this->getMessage(); 13 | } 14 | } -------------------------------------------------------------------------------- /src/Omnipay/Common/Message/CompletePurchaseResponseInterface.php: -------------------------------------------------------------------------------- 1 | 8 | **/ 9 | interface CompletePurchaseResponseInterface { 10 | /** 11 | * 返回是否交易成功 12 | * @return bool 13 | */ 14 | public function isTradeStatusOk(); 15 | } 16 | -------------------------------------------------------------------------------- /src/Omnipay/Alipay/Message/ExpressRefundResponse.php: -------------------------------------------------------------------------------- 1 | 4 | * Date: 14/12/29 5 | * Time: 下午3:05 6 | */ 7 | 8 | namespace Omnipay\Alipay\Message; 9 | 10 | 11 | class ExpressRefundResponse extends PurchaseResponse{ 12 | 13 | /** 14 | * Is the response successful? 15 | * 16 | * @return boolean 17 | */ 18 | public function isSuccessful() 19 | { 20 | // TODO: Implement isSuccessful() method. 21 | } 22 | 23 | public function isRedirect() 24 | { 25 | return true; 26 | } 27 | 28 | 29 | 30 | } -------------------------------------------------------------------------------- /src/Omnipay/Alipay/Message/MobileExpressPurchaseResponse.php: -------------------------------------------------------------------------------- 1 | data; 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "codelint/chinapay", 3 | "description": "Omnipay's gateway implement for chinese payment service like (alipay, wechat, netpay)", 4 | "require": { 5 | "php-http/guzzle6-adapter": "2.0.1", 6 | "omnipay/common": "v3.0.*", 7 | "doctrine/cache": "1.3.1" 8 | }, 9 | "license": "MIT", 10 | "authors": [ 11 | { 12 | "name": "codelint", 13 | "email": "codelint@foxmail.com" 14 | } 15 | ], 16 | "autoload": { 17 | "psr-0": {"Omnipay\\": "src/"}, 18 | "files": [ 19 | "src/Omnipay/Utils/helper.php", 20 | "src/Omnipay/Utils/phpqrcode.php" 21 | ] 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /src/Omnipay/Netpay/Message/NetpayCompletePurchaseResponse.php: -------------------------------------------------------------------------------- 1 | 10 | **/ 11 | class NetpayCompletePurchaseResponse extends AbstractResponse implements CompletePurchaseResponseInterface { 12 | 13 | /** 14 | * 返回是否交易成功 15 | * @return bool 16 | */ 17 | public function isTradeStatusOk() 18 | { 19 | return false; 20 | } 21 | 22 | /** 23 | * Is the response successful? 24 | * 25 | * @return boolean 26 | */ 27 | public function isSuccessful() 28 | { 29 | return false; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/Omnipay/Alipay/DualGateway.php: -------------------------------------------------------------------------------- 1 | setService($this->service_name); 32 | return $this->createRequest('\Omnipay\Alipay\Message\SecuredPurchaseRequest', $parameters); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Omnipay/Wechat/Sdk/NativeCall.php: -------------------------------------------------------------------------------- 1 | returnParameters["return_code"] == "SUCCESS") 12 | { 13 | $this->returnParameters["appid"] = $this->app_id; //公众账号ID 14 | $this->returnParameters["mch_id"] = $this->mch_id; //商户号 15 | $this->returnParameters["nonce_str"] = $this->createNoncestr(); //随机字符串 16 | $this->returnParameters["sign"] = $this->getSign($this->returnParameters); //签名 17 | } 18 | return $this->arrayToXml($this->returnParameters); 19 | } 20 | 21 | /** 22 | * 获取product_id 23 | */ 24 | function getProductId() 25 | { 26 | $product_id = $this->data["product_id"]; 27 | return $product_id; 28 | } 29 | 30 | } -------------------------------------------------------------------------------- /demo/wechat.refund.php: -------------------------------------------------------------------------------- 1 | $_GET['out_trade_no'], 9 | 'transaction_id' => $_GET['transaction_id'], 10 | 'out_refund_no' => $_GET['out_refund_no'], 11 | 'total_fee' => $_GET['total_fee'], 12 | 'refund_fee' => $_GET['refund_fee'] 13 | ]; 14 | 15 | $data = array_filter($data); 16 | 17 | $gateway = new \Omnipay\Wechat\ExpressGateway(); 18 | 19 | 20 | $gateway->setAppId($config['app_id']); 21 | $gateway->setKey($config['pay_sign_key']); 22 | $gateway->setPartner($config['partner']); 23 | $gateway->setPartnerKey($config['partner_key']); 24 | 25 | $gateway->setCertPath($config['cert_path']); 26 | $gateway->setCertKeyPath($config['cert_key_path']); 27 | $gateway->setPubCertPath($config['pub_cert_path']); 28 | 29 | 30 | $req = $gateway->refund($data); 31 | $res = $req->send(); 32 | 33 | echo json_encode($res->getTransactionReference()); -------------------------------------------------------------------------------- /src/Omnipay/Alipay/MobileExpressGateway.php: -------------------------------------------------------------------------------- 1 | createRequest('\Omnipay\Alipay\Message\MobileExpressPurchaseRequest', $parameters); 30 | } 31 | 32 | public function getPrivateKey() 33 | { 34 | return $this->getParameter('private_key'); 35 | } 36 | 37 | public function setPrivateKey($value) 38 | { 39 | $this->setParameter('private_key', $value); 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /src/Omnipay/Baifu/Message/ExpressCompletePurchaseResponse.php: -------------------------------------------------------------------------------- 1 | 10 | **/ 11 | class ExpressCompletePurchaseResponse extends AbstractResponse implements CompletePurchaseResponseInterface{ 12 | 13 | /** 14 | * 返回是否交易成功 15 | * @return bool 16 | */ 17 | public function isTradeStatusOk() 18 | { 19 | $data = $this->getData(); 20 | return ($data['pay_result'] == 1); 21 | } 22 | 23 | /** 24 | * Is the response successful? 25 | * 26 | * @return boolean 27 | */ 28 | public function isSuccessful() 29 | { 30 | return !empty($this->data); 31 | } 32 | 33 | public function getTransactionReference() 34 | { 35 | return $this->getData(); 36 | } 37 | 38 | 39 | } -------------------------------------------------------------------------------- /src/Omnipay/Wechat/Message/WechatPrePurchaseResponse.php: -------------------------------------------------------------------------------- 1 | 8 | **/ 9 | class WechatPrePurchaseResponse extends BaseAbstractResponse { 10 | 11 | public function isRedirect() 12 | { 13 | return false; 14 | } 15 | 16 | /** 17 | * Is the response successful? 18 | * 19 | * @return boolean 20 | */ 21 | public function isSuccessful() 22 | { 23 | return $this->data['return_code'] == 'SUCCESS' && $this->data['result_code'] == 'SUCCESS'; 24 | } 25 | 26 | public function getTransactionReference() 27 | { 28 | return array_only($this->data, array( 29 | 'prepay_id', 'trade_type', 'code_url', 30 | 'appid', 'mch_id', 'device_info', 'nonce_str', 31 | 'sign', 32 | 'result_code', 'err_code', 'err_code_des', 'return_code', 'return_msg' 33 | )); 34 | } 35 | } -------------------------------------------------------------------------------- /src/Omnipay/Netpay/Message/NetpayCompletePurchaseRequest.php: -------------------------------------------------------------------------------- 1 | 10 | **/ 11 | class NetpayCompletePurchaseRequest extends AbstractRequest { 12 | 13 | /** 14 | * Get the raw data array for this message. The format of this varies from gateway to 15 | * gateway, but will usually be either an associative array, or a SimpleXMLElement. 16 | * 17 | * @return mixed 18 | */ 19 | public function getData() 20 | { 21 | // TODO: Implement getData() method. 22 | } 23 | 24 | /** 25 | * Send the request with specified data 26 | * 27 | * @param mixed $data The data to send 28 | * @return ResponseInterface 29 | */ 30 | public function sendData($data) 31 | { 32 | // TODO: Implement sendData() method. 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/Omnipay/Alipay/Message/PurchaseResponse.php: -------------------------------------------------------------------------------- 1 | getRedirectMethod() == 'GET') { 27 | return $this->getRequest()->getEndpoint() . '?' . http_build_query($this->getRedirectData()); 28 | } else { 29 | return $this->getRequest()->getEndpoint(); 30 | } 31 | } 32 | 33 | public function getRedirectMethod() 34 | { 35 | return 'GET'; 36 | } 37 | 38 | public function getRedirectData() 39 | { 40 | return $this->data; 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /src/Omnipay/Alipay/Message/WapExpressPurchaseResponse.php: -------------------------------------------------------------------------------- 1 | getRedirectMethod() == 'GET') { 29 | return $this->getRequest()->getEndpoint() . '?' . http_build_query($this->getRedirectData()); 30 | } else { 31 | return $this->getRequest()->getEndpoint(); 32 | } 33 | } 34 | 35 | public function getRedirectMethod() 36 | { 37 | return 'GET'; 38 | } 39 | 40 | public function getRedirectData() 41 | { 42 | return $this->data; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Omnipay/Alipay/BankGateway.php: -------------------------------------------------------------------------------- 1 | setService($this->service_name); 34 | $this->setParameter('paymethod', 'bankPay'); 35 | if ($this->getParameter('defaultbank') === null) { 36 | throw new InvalidRequestException("The setDefaultBank(x) method is not called."); 37 | } 38 | return $this->createRequest('\Omnipay\Alipay\Message\ExpressPurchaseRequest', $parameters); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /src/Omnipay/Wechat/Message/WechatCompletePurchaseResponse.php: -------------------------------------------------------------------------------- 1 | 10 | **/ 11 | class WechatCompletePurchaseResponse extends BaseAbstractResponse implements CompletePurchaseResponseInterface { 12 | 13 | /** 14 | * Is the response successful? 15 | * 16 | * @return boolean 17 | */ 18 | public function isSuccessful() 19 | { 20 | return $this->data['status']; 21 | } 22 | 23 | /** 24 | * Does the response require a redirect? 25 | * 26 | * @return boolean 27 | */ 28 | public function isRedirect() 29 | { 30 | return false; 31 | } 32 | 33 | /** 34 | * 返回是否交易成功 35 | * @return bool 36 | */ 37 | public function isTradeStatusOk() 38 | { 39 | return $this->data['trade_status_ok']; 40 | } 41 | 42 | public function getMessage() 43 | { 44 | return $this->data['return_msg']; 45 | } 46 | 47 | 48 | } -------------------------------------------------------------------------------- /src/Omnipay/Alipay/Message/WapExpressAuthorizeResponse.php: -------------------------------------------------------------------------------- 1 | request = $request; 19 | $this->data = $data; 20 | } 21 | 22 | /** 23 | * Is the response successful? 24 | * 25 | * @return boolean 26 | */ 27 | public function isSuccessful() 28 | { 29 | if (isset($this->data['request_token']) && $this->data['request_token']) { 30 | return true; 31 | } else { 32 | return false; 33 | } 34 | } 35 | 36 | public function getToken() 37 | { 38 | if ($this->isSuccessful()) { 39 | return $this->data['request_token']; 40 | } else { 41 | return ''; 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/Omnipay/Alipay/Message/ExpressCompletePurchaseResponse.php: -------------------------------------------------------------------------------- 1 | data['verify_success']) { 28 | return true; 29 | } else { 30 | return false; 31 | } 32 | } 33 | 34 | public function isTradeStatusOk() 35 | { 36 | $status = $this->request->getTradeStatus(); 37 | return ($status == 'TRADE_FINISHED' || $status == 'TRADE_SUCCESS'); 38 | } 39 | 40 | public function getResponseText() 41 | { 42 | if ($this->isSuccessful()) { 43 | return 'success'; 44 | } else { 45 | return 'fail'; 46 | } 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/Omnipay/Netpay/Message/NetpayPurchaseResponse.php: -------------------------------------------------------------------------------- 1 | 10 | **/ 11 | class NetpayPurchaseResponse extends AbstractResponse implements RedirectResponseInterface{ 12 | 13 | public function isRedirect(){ 14 | return true; 15 | } 16 | 17 | /** 18 | * Gets the redirect target url. 19 | */ 20 | public function getRedirectUrl() 21 | { 22 | return $this->getRequest()->getEndPoint(); 23 | } 24 | 25 | /** 26 | * Get the required redirect method (either GET or POST). 27 | */ 28 | public function getRedirectMethod() 29 | { 30 | return 'POST'; 31 | } 32 | 33 | /** 34 | * Gets the redirect form data array, if the redirect method is POST. 35 | */ 36 | public function getRedirectData() 37 | { 38 | return $this->getData(); 39 | } 40 | 41 | /** 42 | * Is the response successful? 43 | * 44 | * @return boolean 45 | */ 46 | public function isSuccessful() 47 | { 48 | return false; 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/Omnipay/Wechat/Sdk/OrderQuery.php: -------------------------------------------------------------------------------- 1 | url = "https://api.mch.weixin.qq.com/pay/orderquery"; 11 | //设置curl超时时间 12 | $this->curl_timeout = static::CURL_TIMEOUT; 13 | } 14 | 15 | /** 16 | * 生成接口参数xml 17 | */ 18 | function createXml() 19 | { 20 | try 21 | { 22 | //检测必填参数 23 | if ($this->parameters["out_trade_no"] == null && 24 | $this->parameters["transaction_id"] == null 25 | ) 26 | { 27 | throw new SDKRuntimeException("订单查询接口中,out_trade_no、transaction_id至少填一个!" . "
41 | Demo Entry 演示入口
42 |
43 | demo/index.php : 为demo的入口地址,可以测试支付宝支付,微信支付需要填入相关配置,支付宝配置已经填入
44 |
45 | demo/config.php : 包含了一些通用配置,例如加载库,所需要库在vendor目录里,通过文件中:
46 | require_once('../vendor/autoload.php'); 语句加载
47 |
48 | --------------------------------------------------------------------------------
49 | Modify Alipay/Wechat Config 修改配置
50 |
51 | 修改文件demo/config.php的返回值可修改配置
52 |
53 | --------------------------------------------------------------------------------
54 |
55 | About alipay.wap use:
56 |
57 | demo/alipay.redirect.php : the demo for redirect use 关于如何跳转到支付界面的代码演示
58 |
59 | demo/alipay.notify.php : the demo for notify use 关于如何响应通知的演示
60 |
61 | the return url have the same params as alipay server post to demo/alipay.notify.php when
62 | the return url call.
63 | 当用户支付完成后,返回到return_url指定的路径时,所含参数阿里服务器通知支付结果到alipay.notify.php时,
64 | POST的参数一致。
65 | 微信使用:
66 | $_GET['out_trade_no']: 为订单号,
67 | $_GET['trade_no']: 为流水号,
68 | $_GET['total_fee']为订单金额
69 |
70 | ----------------------------------------------------------------------------------
71 |
72 | About WeChat:
73 |
74 | demo/wechat.redirect.php
75 | show how to redirect to pay by Wechat 支付跳转演示
76 | 注意:这里输入的金额单位以元(接口做了处理,使得网关跳转接口一致使用元作为单位,但微信实际使用“分”
77 | 做单位,因此在响应接口中,微信返回的金额单位为:“分”,不是元)
78 |
79 | demo/wechat.notify.php
80 | show how to react the payment result notify. 响应支付结果
81 |
82 | About return_url:
83 | 支付完成跳转回来,微信使用POST,其参数与[demo/wechat.notify.php]一致。
84 | 微信使用:
85 | $_GET['out_trade_no'] 订单号,
86 | $_GET['bank_billno'] 流水号,
87 | $_GET['product_fee'] 订单金额(单位为分, 注意这里单位与跳转的时候使用的不一致)
88 | 通知/返回 url的其他参数:
89 | $_GET['notify_id'] 消息id
90 | $_GET['transaction_id'] 交易号
91 |
92 | ---------------------------------------------------------------------------------
93 | 通过demo/info.php?out_trade_no=xxxxxxxxxx可以查看支付状态, 返回为一个JSON, 里面记录了
94 | 指定订单号(out_trade_no)的支付情况(跳转时使用的参数)
95 | last_notify: 上一次支付通知的记录(包括通知的url,以及$_GET, $_POST内容)
96 | last_error: 上一次支付通知失败纪录
97 |
98 |
99 |
100 |
101 |
102 |
--------------------------------------------------------------------------------
/demo/wechat.redirect.php:
--------------------------------------------------------------------------------
1 | setAppId($config['app_id']);
30 | $gateway->setKey($config['pay_sign_key']);
31 | $gateway->setPartner($config['partner']);
32 | $gateway->setPartnerKey($config['partner_key']);
33 |
34 | $gateway->setNotifyUrl($config['notify_url']);
35 | $gateway->setReturnUrl($config['return_url']);
36 | $gateway->setReturnUrl($config['cancel_url']);
37 |
38 | $gateway->setCertPath($config['cert_path']);
39 | $gateway->setCertKeyPath($config['cert_key_path']);
40 |
41 | $out_trade_no = $_GET['out_trade_no'];
42 | $opts = array(
43 | 'open_id' => array_get($config, 'open_id', false),
44 | 'subject' => $_GET['subject'],
45 | 'description' => '微信无效',
46 | 'total_fee' => $_GET['total_fee'],
47 | 'out_trade_no' => $out_trade_no,
48 | );
49 | if($type == 'prepay')
50 | {
51 | $res = $gateway->prePurchase(array_add($opts, 'trade_type', 'APP'))->send();
52 | echo json_encode($res->getTransactionReference());
53 | exit(0);
54 | }else{
55 | $res = $gateway->purchase($opts)->send();
56 | }
57 |
58 | // $res = $gateway->prePurchase($opts)->send();
59 | // $ret = $res->getTransactionReference();
60 | // echo $ret;
61 | $cache = get_cache();
62 | $cache->save($out_trade_no, $opts);
63 |
64 | if (!empty($_GET['redirect']))
65 | {
66 | $res->redirect('js');
67 | }
68 |
69 | if (!empty($_GET['link']))
70 | {
71 | $url = $res->getRedirectUrl();
72 | if (empty($_GET['qr']))
73 | {
74 | echo("");
75 | echo("$url");
76 | echo("");
77 | }
78 | else
79 | {
80 | QRcode::png($url);
81 | }
82 | die();
83 | }
84 |
85 | $res->redirect();
86 | } catch (\Exception $e)
87 | {
88 | var_dump($e->getMessage());
89 | }
90 | }
91 |
92 | if($_GET['pay_type'] == 'APP')
93 | {
94 | wechat_redirect($config, 'prepay');
95 | exit();
96 | }
97 |
98 | $jsApi = new \Omnipay\Wechat\Sdk\JsApi();
99 | $jsApi->init(array(
100 | 'app_id' => $config['app_id'],
101 | 'mch_id' => $config['mch_id'],
102 | 'app_secret' => $config['app_secret'],
103 | 'pay_sign_key' => $config['pay_sign_key'],
104 | 'cert_path' => $config['cert_path'],
105 | 'cert_key_path' => $config['cert_key_path'],
106 | ));
107 | if (array_get($_GET, 'code', false))
108 | {
109 | $jsApi->setCode($_GET['code']);
110 | // var_dump($_GET);
111 | // $url = $jsApi->createOauthUrlForOpenid();
112 | //Header('Location: '. $url);
113 | $open_id = $jsApi->getOpenid();
114 | $config['open_id'] = $open_id;
115 | // var_dump($open_id);
116 | wechat_redirect($config);
117 | }
118 | else
119 | {
120 | $r_link = 'http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];
121 | $url = $jsApi->createOauthUrlForCode(urlencode($r_link));
122 | Header('Location: ' . $url);
123 | }
124 |
--------------------------------------------------------------------------------
/src/Omnipay/Alipay/SecuredGateway.php:
--------------------------------------------------------------------------------
1 | setLogisticsFee($fee);
44 | $this->setLogisticsType($type);
45 | $this->setLogisticsPayment($payment);
46 | }
47 |
48 | public function getLogisticsFee()
49 | {
50 | return $this->getParameter('logistics_fee');
51 | }
52 |
53 | public function setLogisticsFee($value)
54 | {
55 | $this->setParameter('logistics_fee', $value);
56 | }
57 |
58 | public function getLogisticsType()
59 | {
60 | return $this->getParameter('logistics_type');
61 | }
62 |
63 | public function setLogisticsType($value)
64 | {
65 | $this->setParameter('logistics_type', $value);
66 | }
67 |
68 | public function getLogisticsPayment()
69 | {
70 | return $this->getParameter('logistics_payment');
71 | }
72 |
73 | public function setLogisticsPayment($value)
74 | {
75 | $this->setParameter('logistics_payment', $value);
76 | }
77 |
78 | public function setReceiveInfo($name, $address, $zip, $phone, $mobile)
79 | {
80 | $this->setReceiveName($name);
81 | $this->setReceiveAddress($address);
82 | $this->setReceiveZip($zip);
83 | $this->setReceivePhone($phone);
84 | $this->setReceiveMobile($mobile);
85 | }
86 |
87 | public function getReceiveName()
88 | {
89 | return $this->getParameter('receive_name');
90 | }
91 |
92 | public function setReceiveName($value)
93 | {
94 | $this->setParameter('receive_name', $value);
95 | }
96 |
97 | public function getReceiveAddress()
98 | {
99 | return $this->getParameter('receive_address');
100 | }
101 |
102 | public function setReceiveAddress($value)
103 | {
104 | $this->setParameter('receive_address', $value);
105 | }
106 |
107 | public function getReceiveZip()
108 | {
109 | return $this->getParameter('receive_zip');
110 | }
111 |
112 | public function setReceiveZip($value)
113 | {
114 | $this->setParameter('receive_zip', $value);
115 | }
116 |
117 | public function getReceivePhone()
118 | {
119 | return $this->getParameter('receive_phone');
120 | }
121 |
122 | public function setReceivePhone($value)
123 | {
124 | $this->setParameter('receive_phone', $value);
125 | }
126 |
127 | public function getReceiveMobile()
128 | {
129 | return $this->getParameter('receive_mobile');
130 | }
131 |
132 | public function setReceiveMobile($value)
133 | {
134 | $this->setParameter('receive_mobile', $value);
135 | }
136 |
137 | public function purchase(array $parameters = array())
138 | {
139 | $this->setService($this->service_name);
140 | return $this->createRequest('\Omnipay\Alipay\Message\SecuredPurchaseRequest', $parameters);
141 | }
142 | }
143 |
--------------------------------------------------------------------------------
/src/Omnipay/Wechat/Message/WechatPrePurchaseRequest.php:
--------------------------------------------------------------------------------
1 |
12 | **/
13 | class WechatPrePurchaseRequest extends BaseAbstractRequest {
14 |
15 | protected $endpoint = 'https://api.mch.weixin.qq.com/pay/unifiedorder';
16 |
17 | protected function getParameter($key)
18 | {
19 | return $this->parameters->get($key);
20 | }
21 |
22 | public function initialize(array $parameters = array())
23 | {
24 | if (null !== $this->response)
25 | {
26 | throw new \RuntimeException('Request cannot be modified after it has been sent!');
27 | }
28 |
29 | $this->parameters = new ParameterBag;
30 | foreach ($parameters as $k => $v)
31 | {
32 | $this->parameters->set($k, $v);
33 | }
34 | return $this;
35 | }
36 |
37 | /**
38 | * Get the raw data array for this message. The format of this varies from gateway to
39 | * gateway, but will usually be either an associative array, or a SimpleXMLElement.
40 | *
41 | * @return mixed
42 | */
43 | public function getData()
44 | {
45 | $this->validate(
46 | 'app_id',
47 | 'app_key',
48 | 'partner',
49 | 'body',
50 | 'out_trade_no',
51 | 'total_fee',
52 | 'spbill_create_ip',
53 | 'notify_url',
54 | 'cert_path',
55 | 'cert_key_path'
56 | );
57 |
58 | $params = array_only($this->parameters->all(), array(
59 | 'app_id', 'app_key', 'partner',
60 | 'body', 'out_trade_no', 'total_fee',
61 | 'spbill_create_ip', 'notify_url', 'trade_type',
62 | 'open_id', 'product_id',
63 | 'device_info', 'attach',
64 | 'time_start', 'time_expire', 'goods_tag', 'cert_path', 'cert_key_path'
65 | ));
66 | $params['appid'] = $params['app_id'];
67 | $params['openid'] = $params['open_id'];
68 | $params['mch_id'] = $params['partner'];
69 | $params['nonstr'] = str_random(8);
70 | $params['time_start'] = date('YmdHis');
71 | $params['trade_type'] = array_get($params, 'trade_type', 'JSAPI');
72 | return array_except($params, ['app_id', 'open_id', 'partner']);
73 | }
74 |
75 | /**
76 | * Send the request with specified data
77 | *
78 | * @param mixed $data The data to send
79 | * @return ResponseInterface
80 | */
81 | public function sendData($data)
82 | {
83 | $unifiedOrder = new UnifiedOrder();
84 | $unifiedOrder->init(array(
85 | 'app_id' => $data['appid'],
86 | 'mch_id' => $data['mch_id'],
87 | 'app_secret' => '',
88 | 'pay_sign_key' => $data['app_key'],
89 | 'cert_path' => $data['cert_path'],
90 | 'cert_key_path' => $data['cert_key_path'],
91 | ));
92 | //sign已填,商户无需重复填写
93 |
94 | $unifiedOrder->setParameter('body', $data['body']); //商品描述
95 | $unifiedOrder->setParameter('out_trade_no', $data['out_trade_no']); //商户订单号
96 | $unifiedOrder->setParameter('total_fee', $data['total_fee']); //总金额
97 | $unifiedOrder->setParameter('notify_url', $data['notify_url']); //通知地址
98 | $unifiedOrder->setParameter('trade_type', $data['trade_type']); //交易类型
99 | if($data['trade_type'] == 'JSAPI')
100 | {
101 | $unifiedOrder->setParameter('openid', $data['openid']);
102 | }
103 |
104 | $ret = $unifiedOrder->getResult();
105 | $this->response = new WechatPrePurchaseResponse($this, $ret);
106 | return $this->response;
107 | }
108 |
109 | }
--------------------------------------------------------------------------------
/src/Omnipay/Alipay/WapExpressGateway.php:
--------------------------------------------------------------------------------
1 | '',
34 | 'key' => '',
35 | 'signType' => 'MD5',
36 | 'inputCharset' => 'utf-8',
37 | );
38 | }
39 |
40 | public function getSellerEmail()
41 | {
42 | return $this->getParameter('seller_email');
43 | }
44 |
45 | public function setSellerEmail($value)
46 | {
47 | return $this->setParameter('seller_email', $value);
48 | }
49 |
50 | public function getPartner()
51 | {
52 | return $this->getParameter('partner');
53 | }
54 |
55 | public function setPartner($value)
56 | {
57 | return $this->setParameter('partner', $value);
58 | }
59 |
60 | public function getKey()
61 | {
62 | return $this->getParameter('key');
63 | }
64 |
65 | public function setKey($value)
66 | {
67 | return $this->setParameter('key', $value);
68 | }
69 |
70 | public function setNotifyUrl($value)
71 | {
72 | return $this->setParameter('notify_url', $value);
73 | }
74 |
75 | public function setReturnUrl($value)
76 | {
77 | return $this->setParameter('return_url', $value);
78 | }
79 |
80 | public function getCancelUrl()
81 | {
82 | return $this->getParameter('cancel_url');
83 | }
84 |
85 | public function setCancelUrl($value)
86 | {
87 | return $this->setParameter('cancel_url', $value);
88 | }
89 |
90 | public function getSignType()
91 | {
92 | return $this->getParameter('sign_type');
93 | }
94 |
95 | public function setSignType($value)
96 | {
97 | return $this->setParameter('sign_type', $value);
98 | }
99 |
100 | public function getInputCharset()
101 | {
102 | return $this->getParameter('input_charset');
103 | }
104 |
105 | public function setInputCharset($value)
106 | {
107 | return $this->setParameter('input_charset', $value);
108 | }
109 |
110 | public function tokenRequest(array $parameters = array())
111 | {
112 | $defaults = array();
113 | $defaults['out_trade_no'] = '1';
114 | $defaults['subject'] = '1';
115 | $defaults['total_fee'] = '1';
116 | $parameters = array_merge($defaults, $parameters);
117 | return $this->createRequest('\Omnipay\Alipay\Message\WapExpressAuthorizeRequest', $parameters);
118 | }
119 |
120 | public function purchase(array $parameters = array())
121 | {
122 | /**
123 | * @var WapExpressAuthorizeResponse $response
124 | */
125 | $response = $this->tokenRequest($parameters)->send();
126 | if ($response->isSuccessful()) {
127 | $parameters['token'] = $response->getToken();
128 | return $this->createRequest('\Omnipay\Alipay\Message\WapExpressPurchaseRequest', $parameters);
129 | } else {
130 | return $this->createRequest('\Omnipay\Alipay\Message\WapExpressPurchaseRequest', $parameters);
131 | }
132 | }
133 |
134 | public function completePurchase(array $parameters = array())
135 | {
136 | return $this->createRequest('\Omnipay\Alipay\Message\WapExpressCompletePurchaseRequest', $parameters);
137 | }
138 | }
139 |
--------------------------------------------------------------------------------
/src/Omnipay/Baifu/Message/ExpressCompletePurchaseRequest.php:
--------------------------------------------------------------------------------
1 |
12 | **/
13 | class ExpressCompletePurchaseRequest extends AbstractRequest {
14 |
15 | protected $endpoint = 'https://www.baifubao.com/api/0/query/0/pay_result_by_order_no';
16 |
17 | public $verifyResponse;
18 |
19 | protected function getParameter($key, $default = '')
20 | {
21 | return $this->parameters->get($key, $default);
22 | }
23 |
24 | public function initialize(array $parameters = array())
25 | {
26 | if (null !== $this->response)
27 | {
28 | throw new \RuntimeException('Request cannot be modified after it has been sent!');
29 | }
30 |
31 | $this->parameters = new ParameterBag;
32 | foreach ($parameters as $k => $v)
33 | {
34 | $this->parameters->set($k, $v);
35 | }
36 | return $this;
37 | }
38 |
39 | /**
40 | * Get the raw data array for this message. The format of this varies from gateway to
41 | * gateway, but will usually be either an associative array, or a SimpleXMLElement.
42 | *
43 | * @return mixed
44 | */
45 | public function getData()
46 | {
47 | $this->validate(
48 | 'key',
49 | 'partner_id',
50 | 'out_trade_no'
51 | );
52 | // $character_set = $this->getParameter('character_set', 'GBK');
53 | $params = [
54 | 'service_code' => 11,
55 | 'sp_no' => $this->getParameter('partner_id'),
56 | 'order_no' => $this->getParameter('out_trade_no'),
57 | 'output_type' => 1,
58 | 'output_charset' => 1,
59 | 'sign_method' => 1,
60 | 'version' => 2
61 | ];
62 | ksort($params);
63 | $sign_str = '';
64 | foreach ($params as $k => $v)
65 | {
66 | $sign_str .= "$k=$v&";
67 | }
68 | $sign_str = $sign_str . 'key=' . $this->getParameter('key');
69 | $params['sign'] = md5($sign_str);
70 | return $params;
71 | }
72 |
73 | /**
74 | * Send the request with specified data
75 | *
76 | * @param mixed $data The data to send
77 | * @return ResponseInterface
78 | */
79 | public function sendData($data)
80 | {
81 | $verify_xml = $this->getVerifyResponse($data);
82 | /* */
83 | $verify_xml = preg_replace('/<\?.*\?>/', '', $verify_xml);
84 | // $xml = simplexml_load_string($verify_xml, 'SimpleXMLElement', LIBXML_NOCDATA);
85 | $data = json_decode(json_encode(simplexml_load_string($verify_xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true);
86 | return $this->response = new ExpressCompletePurchaseResponse($this, $data);
87 | }
88 |
89 | protected function getVerifyResponse($data)
90 | {
91 | $verify_url = $this->endpoint;
92 | $verify_url = $verify_url . '?' . http_build_query($data) ;
93 | $responseTxt = $this->getHttpResponseGET($verify_url);
94 | return $responseTxt;
95 | }
96 |
97 | protected function getHttpResponseGET($url)
98 | {
99 | $curl = curl_init($url);
100 | curl_setopt($curl, CURLOPT_HEADER, 0);
101 | curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
102 | // curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);
103 | // curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
104 | curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
105 | curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
106 | // curl_setopt($curl, CURLOPT_CAINFO, $cacert_url);
107 | $responseText = curl_exec($curl);
108 | curl_close($curl);
109 | return $responseText;
110 | }
111 | }
--------------------------------------------------------------------------------
/src/Omnipay/Alipay/Message/BasePurchaseRequest.php:
--------------------------------------------------------------------------------
1 | validate(
19 | 'service',
20 | 'partner',
21 | 'key',
22 | 'seller_email',
23 | 'notify_url',
24 | 'return_url',
25 | 'out_trade_no',
26 | 'subject',
27 | 'input_charset'
28 | );
29 | }
30 |
31 | public function getService()
32 | {
33 | return $this->getParameter('service');
34 | }
35 |
36 | public function setService($value)
37 | {
38 | $this->setParameter('service', $value);
39 | }
40 |
41 | public function getOutTradeNo()
42 | {
43 | return $this->getParameter('out_trade_no');
44 | }
45 |
46 | public function setOutTradeNo($value)
47 | {
48 | $this->setParameter('out_trade_no', $value);
49 | }
50 |
51 | public function getTransport()
52 | {
53 | return $this->getParameter('transport');
54 | }
55 |
56 | public function setTransport($value)
57 | {
58 | $this->setParameter('transport', $value);
59 | }
60 |
61 | public function getAntiPhishingKey()
62 | {
63 | return $this->getParameter('anti_phishing_key');
64 | }
65 |
66 | public function setAntiPhishingKey($value)
67 | {
68 | $this->setParameter('anti_phishing_key', $value);
69 | }
70 |
71 | public function getExterInvokeIp()
72 | {
73 | return $this->getParameter('exter_invoke_ip');
74 | }
75 |
76 | public function setExterInvokeIp($value)
77 | {
78 | $this->setParameter('exter_invoke_ip', $value);
79 | }
80 |
81 | public function getBody()
82 | {
83 | return $this->getParameter('body');
84 | }
85 |
86 | public function setBody($value)
87 | {
88 | $this->setParameter('body', $value);
89 | }
90 |
91 | public function getPartner()
92 | {
93 | return $this->getParameter('partner');
94 | }
95 |
96 | public function setPartner($value)
97 | {
98 | $this->setParameter('partner', $value);
99 | }
100 |
101 | public function getShowUrl()
102 | {
103 | return $this->getParameter('show_url');
104 | }
105 |
106 | public function setShowUrl($value)
107 | {
108 | $this->setParameter('show_url', $value);
109 | }
110 |
111 | public function getInputCharset()
112 | {
113 | return $this->getParameter('input_charset');
114 | }
115 |
116 | public function setInputCharset($value)
117 | {
118 | $this->setParameter('input_charset', $value);
119 | }
120 |
121 | public function getNotifyUrl()
122 | {
123 | return $this->getParameter('notify_url');
124 | }
125 |
126 | public function setNotifyUrl($value)
127 | {
128 | $this->setParameter('notify_url', $value);
129 | }
130 |
131 | public function getReturnUrl()
132 | {
133 | return $this->getParameter('return_url');
134 | }
135 |
136 | public function setReturnUrl($value)
137 | {
138 | $this->setParameter('return_url', $value);
139 | }
140 |
141 | public function getSellerEmail()
142 | {
143 | return $this->getParameter('seller_email');
144 | }
145 |
146 | public function setSellerEmail($value)
147 | {
148 | $this->setParameter('seller_email', $value);
149 | }
150 |
151 | public function getSubject()
152 | {
153 | return $this->getParameter('subject');
154 | }
155 |
156 | public function setSubject($value)
157 | {
158 | $this->setParameter('subject', $value);
159 | }
160 |
161 | /**
162 | * Send the request with specified data
163 | *
164 | * @param mixed $data The data to send
165 | *
166 | * @return ResponseInterface
167 | */
168 | public function sendData($data)
169 | {
170 | return $this->response = new PurchaseResponse($this, $data);
171 | }
172 |
173 | public function getEndpoint()
174 | {
175 | return $this->liveEndpoint;
176 | }
177 | }
178 |
--------------------------------------------------------------------------------
/src/Omnipay/Wechat/Message/WechatRefundRequest.php:
--------------------------------------------------------------------------------
1 |
13 | **/
14 | class WechatRefundRequest extends BaseAbstractRequest {
15 |
16 | protected $endpoint = 'https://api.mch.weixin.qq.com/secapi/pay/refund';
17 |
18 | const REFUND_SOURCE_UNSETTLED_FUNDS = 'REFUND_SOURCE_UNSETTLED_FUNDS';
19 | const REFUND_SOURCE_RECHARGE_FUNDS = 'REFUND_SOURCE_RECHARGE_FUNDS';
20 |
21 | protected function getParameter($key)
22 | {
23 | return $this->parameters->get($key);
24 | }
25 |
26 | public function initialize(array $parameters = array())
27 | {
28 | if (null !== $this->response)
29 | {
30 | throw new \RuntimeException('Request cannot be modified after it has been sent!');
31 | }
32 |
33 | $this->parameters = new ParameterBag;
34 | foreach ($parameters as $k => $v)
35 | {
36 | $this->parameters->set($k, $v);
37 | }
38 | return $this;
39 | }
40 |
41 | /**
42 | * Get the raw data array for this message. The format of this varies from gateway to
43 | * gateway, but will usually be either an associative array, or a SimpleXMLElement.
44 | *
45 | * @throws \Omnipay\Common\Exception\InvalidRequestException
46 | * @return mixed
47 | */
48 | public function getData()
49 | {
50 | $this->validate(
51 | 'app_id',
52 | 'partner',
53 | 'app_key',
54 | 'out_refund_no',
55 | 'total_fee',
56 | 'refund_fee',
57 | 'cert_path',
58 | 'cert_key_path',
59 | 'pub_cert_path'
60 | );
61 | $params = $this->parameters->all();
62 |
63 | if (empty($params['transaction_id']) && empty($params['out_trade_no']))
64 | {
65 | throw new InvalidRequestException("The transaction_id or out_trade_no parameter is required");
66 | }
67 | $params['appid'] = $params['app_id'];
68 | $params['appkey'] = $params['app_key'];
69 | $params['mch_id'] = $params['partner'];
70 | $params['op_user_id'] = array_get($params, 'op_user_id', $params['partner']);
71 | $params['refund_account'] = array_get($params, 'refund_account', static::REFUND_SOURCE_RECHARGE_FUNDS);
72 | $params = array_only($params, array(
73 | 'appid', 'appkey',
74 | 'refund_fee', 'total_fee', 'out_trade_no',
75 | 'transaction_id', 'op_user_id', 'out_refund_no',
76 | 'noncestr', 'timestamp', 'mch_id', 'cert_path', 'cert_key_path', 'pub_cert_path', 'refund_account'
77 | ));
78 | return $params;
79 | }
80 |
81 | /**
82 | * Send the request with specified data
83 | *
84 | * @param mixed $data The data to send
85 | * @return ResponseInterface
86 | */
87 | public function sendData($data)
88 | {
89 | $refund = new Refund();
90 | $refund->init(array(
91 | 'app_id' => $data['appid'],
92 | 'mch_id' => $data['mch_id'],
93 | 'app_secret' => '',
94 | 'pay_sign_key' => $data['appkey'],
95 | 'cert_path' => $data['cert_path'],
96 | 'cert_key_path' => $data['cert_key_path'],
97 | 'pub_cert_path' => $data['pub_cert_path']
98 | ));
99 | //sign已填,商户无需重复填写
100 | if (!empty($data['out_trade_no']))
101 | {
102 | $refund->setParameter('out_trade_no', $data['out_trade_no']); //商户订单号
103 | }
104 | if (!empty($data['transaction_id']))
105 | {
106 | $refund->setParameter('transaction_id', $data['transaction_id']); //商户订单号
107 | }
108 | $refund->setParameter('total_fee', $data['total_fee']); //总金额
109 | $refund->setParameter('refund_fee', $data['refund_fee']); //退款金额
110 | $refund->setParameter('out_refund_no', $data['out_refund_no']); //退款单号
111 | $refund->setParameter('op_user_id', $data['op_user_id']); //交易类型
112 | $refund->setParameter('refund_account', $data['refund_account']);
113 |
114 | $ret = $refund->getResult();
115 | $this->response = new WechatRefundResponse($this, $ret);
116 | return $this->response;
117 | }
118 | }
--------------------------------------------------------------------------------
/src/Omnipay/Cmpay/ExpressGateway.php:
--------------------------------------------------------------------------------
1 |
10 | **/
11 | class ExpressGateway extends AbstractGateway {
12 |
13 | /**
14 | * Get gateway display name
15 | *
16 | * This can be used by carts to get the display name for each gateway.
17 | */
18 | public function getName()
19 | {
20 | return 'CM_Express';
21 | }
22 |
23 | /**
24 | * Define gateway parameters, in the following format:
25 | *
26 | * array(
27 | * 'username' => '', // string variable
28 | * 'testMode' => false, // boolean variable
29 | * 'landingPage' => array('billing', 'login'), // enum variable, first item is default
30 | * );
31 | */
32 | public function getDefaultParameters()
33 | {
34 | return [
35 | 'character_set' => '02',
36 | 'sign_type' => 'MD5',
37 | 'request_id' => time(),
38 | 'type' => 'DirectPayConfirm',
39 | 'version' => '2.0.0'
40 | ];
41 | }
42 |
43 | function setKey($filepath)
44 | {
45 | $this->setParameter('app_key', $filepath);
46 | }
47 |
48 | function getKey()
49 | {
50 | return $this->getParameter('app_key');
51 | }
52 |
53 | function getPartner()
54 | {
55 | return $this->getParameter('app_id');
56 | }
57 |
58 | function setPartner($id)
59 | {
60 | $this->setParameter('app_id', $id);
61 | }
62 |
63 | function getNotifyUrl()
64 | {
65 | return $this->getParameter('notify_url');
66 | }
67 |
68 | function setNotifyUrl($url)
69 | {
70 | $this->setParameter('notify_url', $url);
71 | }
72 |
73 | function setReturnUrl($url)
74 | {
75 | $this->setParameter('return_url', $url);
76 | }
77 |
78 | function getReturnUrl($url)
79 | {
80 | return $this->getParameter('return_url');
81 | }
82 |
83 | function setClientIP($ip)
84 | {
85 | $this->setParameter('client_ip', $ip);
86 | }
87 |
88 | function getClientIP()
89 | {
90 | return $this->getParameter('client_ip');
91 | }
92 |
93 | public function purchase(array $parameters = [])
94 | {
95 | return $this->createRequest('\Omnipay\Cmpay\Message\ExpressPurchaseRequest', $parameters);
96 | }
97 |
98 | public function completePurchase(array $params = array())
99 | {
100 | try
101 | {
102 | $merchantId = $params["merchantId"];
103 | $payNo = $params["payNo"];
104 | $returnCode = $params["returnCode"];
105 | $message = $params["message"];
106 | $signType = $params["signType"];
107 | $type = $params["type"];
108 | $version = $params["version"];
109 | $amount = $params["amount"];
110 | $amtItem = $params["amtItem"];
111 | $bankAbbr = $params["bankAbbr"];
112 | $mobile = $params["mobile"];
113 | $orderId = $params["orderId"];
114 | $payDate = $params["payDate"];
115 | $accountDate = $params["accountDate"];
116 | $reserved1 = $params["reserved1"];
117 | $reserved2 = $params["reserved2"];
118 | $status = $params["status"];
119 | // $payType = $params["payType"];
120 | $orderDate = $params["orderDate"];
121 | $fee = $params["fee"];
122 | $vhmac = $params["hmac"];
123 |
124 | if ($returnCode != 000000)
125 | {
126 | //此处表示后台通知产生错误
127 | // echo $returnCode . decodeUtf8($message);
128 | return [
129 | 'status' => false,
130 | 'message' => $returnCode . decodeUtf8($message)
131 | ];
132 | }
133 |
134 | $signData = $merchantId . $payNo . $returnCode . $message
135 | . $signType . $type . $version . $amount
136 | . $amtItem . $bankAbbr . $mobile . $orderId
137 | . $payDate . $accountDate . $reserved1 . $reserved2
138 | . $status . $orderDate . $fee;
139 | $hmac = Utils::MD5sign($this->getParameter('app_key'), $signData);
140 |
141 | if ($hmac != $vhmac)
142 | //此处无法信息数据来自手机支付平台
143 | return [
144 | 'status' => false,
145 | 'message' => '验签失败'
146 | ];
147 | else
148 | {
149 | return [
150 | 'status' => true,
151 | 'message' => 'SUCCESS'
152 | ];
153 | }
154 | } catch (\Exception $e)
155 | {
156 | return ['status' => false, 'message' => $e->getLine() . ':' . $e->getMessage()];
157 | }
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/src/Omnipay/Alipay/BaseAbstractGateway.php:
--------------------------------------------------------------------------------
1 | '',
17 | 'key' => '',
18 | 'signType' => 'MD5',
19 | 'inputCharset' => 'utf-8',
20 | 'transport' => 'http',
21 | );
22 | }
23 |
24 | public function getPartner()
25 | {
26 | return $this->getParameter('partner');
27 | }
28 |
29 | public function setPartner($value)
30 | {
31 | return $this->setParameter('partner', $value);
32 | }
33 |
34 | public function getKey()
35 | {
36 | return $this->getParameter('key');
37 | }
38 |
39 | public function setKey($value)
40 | {
41 | return $this->setParameter('key', $value);
42 | }
43 |
44 | public function setNotifyUrl($value)
45 | {
46 | return $this->setParameter('notify_url', $value);
47 | }
48 |
49 | public function setReturnUrl($value)
50 | {
51 | return $this->setParameter('return_url', $value);
52 | }
53 |
54 | public function getSignType()
55 | {
56 | return $this->getParameter('sign_type');
57 | }
58 |
59 | public function setSignType($value)
60 | {
61 | return $this->setParameter('sign_type', $value);
62 | }
63 |
64 | public function getInputCharset()
65 | {
66 | return $this->getParameter('input_charset');
67 | }
68 |
69 | public function setInputCharset($value)
70 | {
71 | return $this->setParameter('input_charset', $value);
72 | }
73 |
74 | public function getTransport()
75 | {
76 | return $this->getParameter('transport');
77 | }
78 |
79 | public function setTransport($value)
80 | {
81 | return $this->setParameter('transport', $value);
82 | }
83 |
84 | public function getAntiPhishingKey()
85 | {
86 | return $this->getParameter('anti_phishing_key');
87 | }
88 |
89 | public function setAntiPhishingKey($value)
90 | {
91 | return $this->setParameter('anti_phishing_key', $value);
92 | }
93 |
94 | public function getExterInvokeIp()
95 | {
96 | return $this->getParameter('exter_invoke_ip');
97 | }
98 |
99 | public function setExterInvokeIp($value)
100 | {
101 | return $this->setParameter('exter_invoke_ip', $value);
102 | }
103 |
104 | public function getBody()
105 | {
106 | return $this->getParameter('body');
107 | }
108 |
109 | public function setBody($value)
110 | {
111 | return $this->setParameter('body', $value);
112 | }
113 |
114 | public function getShowUrl()
115 | {
116 | return $this->getParameter('show_url');
117 | }
118 |
119 | public function setShowUrl($value)
120 | {
121 | return $this->setParameter('show_url', $value);
122 | }
123 |
124 | public function getSellerEmail()
125 | {
126 | return $this->getParameter('seller_email');
127 | }
128 |
129 | public function setSellerEmail($value)
130 | {
131 | $this->setParameter('seller_email', $value);
132 | }
133 |
134 | public function getService()
135 | {
136 | return $this->getParameter('service');
137 | }
138 |
139 | public function setService($value)
140 | {
141 | $this->setParameter('service', $value);
142 | }
143 |
144 | public function getDefaultBank()
145 | {
146 | return $this->getParameter('default_bank');
147 | }
148 |
149 | public function setDefaultBank($value)
150 | {
151 | $this->setParameter('default_bank', $value);
152 | }
153 |
154 | public function getPayMethod()
155 | {
156 | return $this->getParameter('pay_method');
157 | }
158 |
159 | public function setPayMethod($value)
160 | {
161 | $this->setParameter('pay_method', $value);
162 | }
163 |
164 | public function purchase(array $parameters = array())
165 | {
166 | return $this->createRequest('\Omnipay\Alipay\Message\ExpressPurchaseRequest', $parameters);
167 | }
168 |
169 | /**
170 | * @param array $parameters exp: ['refund_data' => [ [ 'trade_no' => 'alipay trade no', 'total_fee' => 'the fee to refund', 'memo' => ''] ] ]
171 | * @throws \RuntimeException
172 | */
173 | public function refund(array $parameters = array())
174 | {
175 | throw new \RuntimeException('Do not support refund');
176 | }
177 |
178 | public function completePurchase(array $parameters = array())
179 | {
180 | return $this->createRequest('\Omnipay\Alipay\Message\ExpressCompletePurchaseRequest', $parameters);
181 | }
182 |
183 | public function completeRefund(array $parameters = array())
184 | {
185 | return $this->createRequest('\Omnipay\Alipay\Message\ExpressCompleteRefundRequest', $parameters);
186 | }
187 | }
188 |
--------------------------------------------------------------------------------
/src/Omnipay/Alipay/Message/SecuredPurchaseRequest.php:
--------------------------------------------------------------------------------
1 | validate(
16 | 'price',
17 | 'quantity',
18 | 'logistics_fee',
19 | 'logistics_type',
20 | 'receive_name',
21 | 'receive_address',
22 | 'receive_zip',
23 | 'receive_phone',
24 | 'receive_mobile'
25 | );
26 | }
27 |
28 | /**
29 | * Get the raw data array for this message. The format of this varies from gateway to
30 | * gateway, but will usually be either an associative array, or a SimpleXMLElement.
31 | *
32 | * @return mixed
33 | */
34 | public function getData()
35 | {
36 | $this->validateData();
37 | $data = array(
38 | "service" => $this->getService(),
39 | "partner" => $this->getPartner(),
40 | "payment_type" => 1,
41 | "notify_url" => $this->getNotifyUrl(),
42 | "return_url" => $this->getReturnUrl(),
43 | "seller_email" => $this->getSellerEmail(),
44 | "out_trade_no" => $this->getOutTradeNo(),
45 | "subject" => $this->getSubject(),
46 | "price" => $this->getPrice(),
47 | "quantity" => $this->getQuantity(),
48 | "logistics_fee" => $this->getLogisticsFee(),
49 | "logistics_type" => $this->getLogisticsType(),
50 | "logistics_payment" => $this->getLogisticsPayment(),
51 | "body" => $this->getBody(),
52 | "show_url" => $this->getShowUrl(),
53 | "receive_name" => $this->getReceiveName(),
54 | "receive_address" => $this->getReceiveAddress(),
55 | "receive_zip" => $this->getReceiveZip(),
56 | "receive_phone" => $this->getReceivePhone(),
57 | "receive_mobile" => $this->getReceiveMobile(),
58 | "_input_charset" => $this->getInputCharset()
59 | );
60 | $data = array_filter($data);
61 | $data['sign'] = $this->getParamsSignature($data);
62 | $data['sign_type'] = $this->getSignType();
63 | return $data;
64 | }
65 |
66 | public function getPrice()
67 | {
68 | return $this->getParameter('price');
69 | }
70 |
71 | public function setPrice($value)
72 | {
73 | $this->setParameter('price', $value);
74 | }
75 |
76 | public function getQuantity()
77 | {
78 | return $this->getParameter('quantity');
79 | }
80 |
81 | public function setQuantity($value)
82 | {
83 | $this->setParameter('quantity', $value);
84 | }
85 |
86 | public function getLogisticsFee()
87 | {
88 | return $this->getParameter('logistics_fee');
89 | }
90 |
91 | public function setLogisticsFee($value)
92 | {
93 | $this->setParameter('logistics_fee', $value);
94 | }
95 |
96 | public function getLogisticsType()
97 | {
98 | return $this->getParameter('logistics_type');
99 | }
100 |
101 | public function setLogisticsType($value)
102 | {
103 | $this->setParameter('logistics_type', $value);
104 | }
105 |
106 | public function getLogisticsPayment()
107 | {
108 | return $this->getParameter('logistics_payment');
109 | }
110 |
111 | public function setLogisticsPayment($value)
112 | {
113 | $this->setParameter('logistics_payment', $value);
114 | }
115 |
116 | public function getReceiveName()
117 | {
118 | return $this->getParameter('receive_name');
119 | }
120 |
121 | public function setReceiveName($value)
122 | {
123 | $this->setParameter('receive_name', $value);
124 | }
125 |
126 | public function getReceiveAddress()
127 | {
128 | return $this->getParameter('receive_address');
129 | }
130 |
131 | public function setReceiveAddress($value)
132 | {
133 | $this->setParameter('receive_address', $value);
134 | }
135 |
136 | public function getReceiveZip()
137 | {
138 | return $this->getParameter('receive_zip');
139 | }
140 |
141 | public function setReceiveZip($value)
142 | {
143 | $this->setParameter('receive_zip', $value);
144 | }
145 |
146 | public function getReceivePhone()
147 | {
148 | return $this->getParameter('receive_phone');
149 | }
150 |
151 | public function setReceivePhone($value)
152 | {
153 | $this->setParameter('receive_phone', $value);
154 | }
155 |
156 | public function getReceiveMobile()
157 | {
158 | return $this->getParameter('receive_mobile');
159 | }
160 |
161 | public function setReceiveMobile($value)
162 | {
163 | $this->setParameter('receive_mobile', $value);
164 | }
165 | }
166 |
--------------------------------------------------------------------------------
/src/Omnipay/Cmpay/Utils.php:
--------------------------------------------------------------------------------
1 |
8 | **/
9 | class Utils {
10 |
11 |
12 | /*
13 | 功能 发送HTTP请求
14 | URL 请求地址
15 | data 请求数据数组
16 | */
17 | static function POSTDATA($url, $data)
18 | {
19 | $url = parse_url($url);
20 | if (!$url)
21 | {
22 | return "couldn't parse url";
23 | }
24 | if (!isset($url['port']))
25 | {
26 | $url['port'] = "";
27 | }
28 |
29 | if (!isset($url['query']))
30 | {
31 | $url['query'] = "";
32 | }
33 |
34 |
35 | $encoded = "";
36 |
37 | while (list($k, $v) = each($data))
38 | {
39 | $encoded .= ($encoded ? "&" : "");
40 | $encoded .= rawurlencode($k) . "=" . rawurlencode($v);
41 | }
42 | $urlHead = null;
43 | $urlPort = $url['port'];
44 | if ($url['scheme'] == "https")
45 | {
46 | $urlHead = "ssl://" . $url['host'];
47 | if ($url['port'] == null || $url['port'] == 0)
48 | {
49 | $urlPort = 443;
50 | }
51 | }
52 | else
53 | {
54 | $urlHead = $url['host'];
55 | if ($url['port'] == null || $url['port'] == 0)
56 | {
57 | $urlPort = 80;
58 | }
59 | }
60 | $fp = fsockopen($urlHead, $urlPort);
61 |
62 | if (!$fp) return "Failed to open socket to $url[host]";
63 |
64 | $tmp = "";
65 | $tmp .= sprintf("POST %s%s%s HTTP/1.0\r\n", $url['path'], $url['query'] ? "?" : "", $url['query']);
66 | $tmp .= "Host: $url[host]\r\n";
67 | $tmp .= "Content-type: application/x-www-form-urlencoded\r\n";
68 | $tmp .= "Content-Length: " . strlen($encoded) . "\r\n";
69 | $tmp .= "Connection: close\r\n\r\n";
70 | $tmp .= "$encoded\r\n";
71 | fputs($fp, $tmp);
72 |
73 | $line = fgets($fp, 1024);
74 |
75 | if (!preg_match("#^HTTP/1\.. 200#i", $line))
76 | {
77 | $logstr = "MSG" . $line;
78 | return array("FLAG" => 0, "MSG" => $line);
79 | }
80 |
81 | $results = "";
82 | $inheader = 1;
83 | while (!feof($fp))
84 | {
85 | $line = fgets($fp, 1024);
86 | if ($inheader && ($line == "\n" || $line == "\r\n"))
87 | {
88 | $inheader = 0;
89 | }
90 | elseif (!$inheader)
91 | {
92 | $results .= $line;
93 | }
94 | }
95 | fclose($fp);
96 | return array("FLAG" => 1, "MSG" => $results);
97 | }
98 |
99 | //MD5方式签名
100 | static function MD5sign($okey, $odata)
101 | {
102 | $signdata = static::hmac("", $odata);
103 | return static::hmac($okey, $signdata);
104 | }
105 |
106 | static function hmac($key, $data)
107 | {
108 | $key = iconv('gb2312', 'utf-8', $key);
109 | $data = iconv('gb2312', 'utf-8', $data);
110 | $b = 64;
111 | if (strlen($key) > $b)
112 | {
113 | $key = pack("H*", md5($key));
114 | }
115 | $key = str_pad($key, $b, chr(0x00));
116 | $ipad = str_pad('', $b, chr(0x36));
117 | $opad = str_pad('', $b, chr(0x5c));
118 | $k_ipad = $key ^ $ipad;
119 | $k_opad = $key ^ $opad;
120 | return md5($k_opad . pack("H*", md5($k_ipad . $data)));
121 | }
122 |
123 | /*
124 | 功能 把http请求返回数组 格式化成数组
125 | */
126 | static function parseRecv($source)
127 | {
128 | $ret = array();
129 | $temp = explode("&", $source);
130 |
131 | foreach ($temp as $value)
132 | {
133 | $index = strpos($value, "=");
134 | $_key = substr($value, 0, $index);
135 | $_value = substr($value, $index + 1);
136 | $ret[$_key] = $_value;
137 | }
138 |
139 | return $ret;
140 | }
141 |
142 | /*
143 | 功能:把UTF-8 编号数据转换成 GB2312 忽略转换错误
144 | */
145 | static function decodeUtf8($source)
146 | {
147 | $temp = urldecode($source);
148 | $ret = iconv("UTF-8", "GB2312//IGNORE", $temp);
149 | return $ret;
150 | }
151 |
152 | /*获取用户IP地址*/
153 | static function getClientIP()
154 | {
155 | if (!empty($_SERVER["HTTP_CLIENT_IP"]))
156 | {
157 | $cip = $_SERVER["HTTP_CLIENT_IP"];
158 | }
159 | else if (!empty($_SERVER["HTTP_X_FORWARDED_FOR"]))
160 | {
161 | $cip = $_SERVER["HTTP_X_FORWARDED_FOR"];
162 | }
163 | else if (!empty($_SERVER["REMOTE_ADDR"]))
164 | {
165 | $cip = $_SERVER["REMOTE_ADDR"];
166 | }
167 | else
168 | {
169 | $cip = "unknown";
170 | }
171 | return $cip;
172 |
173 | }
174 |
175 | //返回URL处理
176 | static function parseUrl($payUrl)
177 | {
178 | $temp = explode("付款中...
133 | 134 | 137 | '; 138 | } 139 | 140 | protected function redirect_js() 141 | { 142 | return '(function(){ 143 | var data = %1$s; 144 | 145 | setTimeout(function(){ 146 | if(typeof WeixinJSBridge == "undefined"){ 147 | return setTimeout(arguments.callee, 200); 148 | } 149 | WeixinJSBridge.invoke( 150 | "getBrandWCPayRequest",data,function(res){ 151 | // 返回 res.err_msg,取值 152 | // get_brand_wcpay_request:cancel 用户取消 153 | // get_brand_wcpay_request:fail 发送失败 154 | // get_brand_wcpay_request:ok 发送成功 155 | if(res.err_msg == "get_brand_wcpay_request:ok"){ 156 | alert("支付成功"); 157 | window.location.href = "%2$s"; 158 | }else if(res.err_msg == "get_brand_wcpay_request:cancel"){ 159 | alert("支付取消"); 160 | window.location.href = "%3$s"; 161 | }else{ 162 | alert("支付失败(" + res["err_msg"] + ")"); 163 | window.location.href = "%4$s"; 164 | } 165 | //WeixinJSBridge.log(res.err_msg); alert(res.err_code+res.err_desc); 166 | }); 167 | 168 | }, 200); 169 | })();'; 170 | } 171 | 172 | public function setReturnUrl($url) 173 | { 174 | $this->return_url = $url; 175 | } 176 | 177 | public function setCancelUrl($url) 178 | { 179 | $this->cancel_url = $url; 180 | } 181 | 182 | public function setFailUrl($url) 183 | { 184 | $this->fail_url = $url; 185 | } 186 | } 187 | -------------------------------------------------------------------------------- /src/Omnipay/Alipay/Message/WapExpressAuthorizeRequest.php: -------------------------------------------------------------------------------- 1 | validate( 25 | 'notify_url', 26 | 'return_url', 27 | 'seller_email', 28 | 'out_trade_no', 29 | 'subject', 30 | 'total_fee', 31 | 'cancel_url' 32 | ); 33 | $format = '');
249 | echo $wording . "";
250 | var_dump($err);
251 | print_r('');
252 | }
253 | }
254 |
255 |
256 |
257 |
258 |
259 |
260 |
--------------------------------------------------------------------------------
/demo/alipay.redirect.php.html:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | 34 | <?php 35 | $config = require_once('./config.php'); 36 | 37 | $config = $config['alipay']; 38 | 39 | /** 40 | * 支付宝: 跳转到支付界面 41 | * @param $config 42 | */ 43 | function alipay_redirect($config) 44 | { 45 | /* 46 | * @var Omnipay\Alipay\WapExpressGateway 47 | */ 48 | try 49 | { 50 | // $gateway = \Omnipay\Omnipay::create('Alipay_WapExpress') 51 | $gateway = new \Omnipay\Alipay\WapExpressGateway(); 52 | $gateway->setPartner($config['partner']); 53 | $gateway->setKey($config['key']); 54 | $gateway->setSellerEmail($config['seller_email']); 55 | $gateway->setNotifyUrl($config['notify_url']); 56 | $gateway->setReturnUrl($config['return_url']); 57 | $gateway->setCancelUrl($config['cancel_url']); 58 | $opts = array( 59 | 'subject' => $_GET['subject'], 60 | 'description' => '暂无', 61 | 'total_fee' => $_GET['total_fee'], 62 | 'out_trade_no' => $_GET['out_trade_no'], 63 | ); 64 | $res = $gateway->purchase($opts)->send(); 65 | $cache = get_cache(); 66 | $cache->save($_GET['out_trade_no'], $opts); 67 | $res->redirect(); 68 | // header("Content-type: application/json"); 69 | // echo json_encode([ 70 | // 'url' => $res->getRedirectUrl(), 71 | // 'opts' => $opts, 72 | // 'config' => $config, 73 | // 'info_url' => 'http://' . $_SERVER['HTTP_HOST'] . '/demo/info.php?out_trade_no=' . $out_trade_no, 74 | // ]); 75 | } catch (\Exception $e) 76 | { 77 | var_dump($e->getMessage()); 78 | } 79 | } 80 | 81 | alipay_redirect($config); 82 |83 | 84 | 85 | 86 | -------------------------------------------------------------------------------- /demo/wechat.redirect.php.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 |
34 | <?php 35 | /* 36 | * notice : 37 | * return url must not have any url param 38 | * total_fee WeChat use Fen not Yuan as unit 39 | */ 40 | 41 | $config = require_once('./config.php'); 42 | 43 | $config = $config['wechat']; 44 | 45 | /** 46 | * 跳转到支付界面 47 | * @param $config 48 | */ 49 | function wechat_redirect($config) 50 | { 51 | /* 52 | * @var Omnipay\Wechat\ExpressGateway 53 | */ 54 | try 55 | { 56 | // $gateway = \Omnipay\Omnipay::create('Wechat_Express'); 57 | $gateway = new \Omnipay\Wechat\ExpressGateway(); 58 | 59 | $gateway->setAppId($config['app_id']); 60 | $gateway->setKey($config['pay_sign_key']); 61 | $gateway->setPartner($config['partner']); 62 | $gateway->setPartnerKey($config['partner_key']); 63 | 64 | $gateway->setNotifyUrl($config['notify_url']); 65 | $gateway->setReturnUrl($config['return_url']); 66 | $gateway->setReturnUrl($config['cancel_url']); 67 | 68 | $out_trade_no = $_GET['out_trade_no']; 69 | $opts = array( 70 | 'subject' => $_GET['subject'], 71 | 'description' => '微信无效', 72 | 'total_fee' => $_GET['total_fee'], 73 | 'out_trade_no' => $out_trade_no, 74 | ); 75 | $res = $gateway->purchase($opts)->send(); 76 | $cache = get_cache(); 77 | $cache->save($out_trade_no, $opts); 78 | 79 | if (!empty($_GET['redirect'])) 80 | { 81 | $res->redirect('js'); 82 | } 83 | $res->redirect(); 84 | } catch (\Exception $e) 85 | { 86 | var_dump($e->getMessage()); 87 | } 88 | } 89 | 90 | wechat_redirect($config); 91 |92 | 93 | 94 | 95 | --------------------------------------------------------------------------------