diff --git a/public/php_sdk_v3.0.10/doc/README b/public/php_sdk_v3.0.10/doc/README new file mode 100755 index 0000000000000000000000000000000000000000..8f4a132f92397a21d257142a3ee51a66a3007284 --- /dev/null +++ b/public/php_sdk_v3.0.10/doc/README @@ -0,0 +1,55 @@ +SDK +体验地址 +http://paysdk.weixin.qq.com/ + +快速搭建指南 +①、安装配置nginx+phpfpm+php +②、建SDK解压到网站根目录 +③、修改lib/WxPay.Config.php为自己申请的商户号的信息(配置详见说明) +⑤、下载证书替换cert下的文件 +⑥、搭建完成 + +SDK目录结构 +|-- lib +|-- logs +`-- example + + +目录功能简介 +lib +API接口封装代码 +WxPay.Api.php 包括所有微信支付API接口的封装 +WxPay.Config.Interface.php 商户配置 , 业务需要从这里继承(请注意保管自己的密钥/证书等) +WxPay.Data.php 输入参数封装 +WxPay.Exception.php 异常类 +WxPay.Notify.php 回调通知基类 + +cert +证书存放路径,证书可以登录商户平台https://pay.weixin.qq.com/index.php/account/api_cert下载 +注意: +1.证书文件不能放在web服务器虚拟目录,应放在有访问权限控制的目录中,防止被他人下载; +2.建议将证书文件名改为复杂且不容易猜测的文件名; +3.商户服务器要做好病毒和木马防护工作,不被非法侵入者窃取证书文件。 + +example +样例程序代码路径 + +example/phpqrcode +开源二维码php代码 + +logs +日志文件 + +※配置指南 +MCHID = '1225312702'; +这里填开户邮件中的商户号 + +APPID = 'wx426b3015555a46be'; +这里填开户邮件中的(公众账号APPID或者应用APPID) + +KEY = 'e10adc3949ba59abbe56e057f20f883e' +这里请使用商户平台登录账户和密码登录http://pay.weixin.qq.com 平台设置的“API密钥”,为了安全,请设置为32字符串。 + +APPSECRET = '01c6d59a3f9024db6336662ac95c8e74' +改参数在JSAPI支付(open平台账户不能进行JSAPI支付)的时候需要用来获取用户openid,可使用APPID对应的公众平台登录http://mp.weixin.qq.com 的开发者中心获取AppSecret。 + diff --git a/public/php_sdk_v3.0.10/doc/README.doc b/public/php_sdk_v3.0.10/doc/README.doc new file mode 100755 index 0000000000000000000000000000000000000000..ea33f69ce2f8c8de2f32f661a27ecf13f6ef3c76 Binary files /dev/null and b/public/php_sdk_v3.0.10/doc/README.doc differ diff --git a/public/php_sdk_v3.0.10/example/WxPay.Config.php b/public/php_sdk_v3.0.10/example/WxPay.Config.php new file mode 100755 index 0000000000000000000000000000000000000000..bba5440e9ff071182c6778a39fbcf37e9c16c303 --- /dev/null +++ b/public/php_sdk_v3.0.10/example/WxPay.Config.php @@ -0,0 +1,116 @@ +_CreateOauthUrlForCode($baseUrl); + Header("Location: $url"); + exit(); + } else { + //鑾峰彇code鐮侊紝浠ヨ幏鍙杘penid + $code = $_GET['code']; + $openid = $this->getOpenidFromMp($code); + return $openid; + } + } + + /** + * + * 鑾峰彇jsapi鏀粯鐨勫弬鏁 + * @param array $UnifiedOrderResult 缁熶竴鏀粯鎺ュ彛杩斿洖鐨勬暟鎹 + * @throws WxPayException + * + * @return json鏁版嵁锛屽彲鐩存帴濉叆js鍑芥暟浣滀负鍙傛暟 + */ + public function GetJsApiParameters($UnifiedOrderResult) + { + if(!array_key_exists("appid", $UnifiedOrderResult) + || !array_key_exists("prepay_id", $UnifiedOrderResult) + || $UnifiedOrderResult['prepay_id'] == "") + { + throw new WxPayException("鍙傛暟閿欒"); + } + + $jsapi = new WxPayJsApiPay(); + $jsapi->SetAppid($UnifiedOrderResult["appid"]); + $timeStamp = time(); + $jsapi->SetTimeStamp("$timeStamp"); + $jsapi->SetNonceStr(WxPayApi::getNonceStr()); + $jsapi->SetPackage("prepay_id=" . $UnifiedOrderResult['prepay_id']); + + $config = new WxPayConfig(); + $jsapi->SetPaySign($jsapi->MakeSign($config)); + $parameters = json_encode($jsapi->GetValues()); + return $parameters; + } + + /** + * + * 閫氳繃code浠庡伐浣滃钩鍙拌幏鍙杘penid鏈哄櫒access_token + * @param string $code 寰俊璺宠浆鍥炴潵甯︿笂鐨刢ode + * + * @return openid + */ + public function GetOpenidFromMp($code) + { + $url = $this->__CreateOauthUrlForOpenid($code); + + //鍒濆鍖朿url + $ch = curl_init(); + $curlVersion = curl_version(); + $config = new WxPayConfig(); + $ua = "WXPaySDK/3.0.9 (".PHP_OS.") PHP/".PHP_VERSION." CURL/".$curlVersion['version']." " + .$config->GetMerchantId(); + + //璁剧疆瓒呮椂 + curl_setopt($ch, CURLOPT_TIMEOUT, $this->curl_timeout); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_SSL_VERIFYPEER,FALSE); + curl_setopt($ch, CURLOPT_SSL_VERIFYHOST,FALSE); + curl_setopt($ch, CURLOPT_USERAGENT, $ua); + curl_setopt($ch, CURLOPT_HEADER, FALSE); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + + $proxyHost = "0.0.0.0"; + $proxyPort = 0; + $config->GetProxy($proxyHost, $proxyPort); + if($proxyHost != "0.0.0.0" && $proxyPort != 0){ + curl_setopt($ch,CURLOPT_PROXY, $proxyHost); + curl_setopt($ch,CURLOPT_PROXYPORT, $proxyPort); + } + //杩愯curl锛岀粨鏋滀互jason褰㈠紡杩斿洖 + $res = curl_exec($ch); + curl_close($ch); + //鍙栧嚭openid + $data = json_decode($res,true); + $this->data = $data; + $openid = $data['openid']; + return $openid; + } + + /** + * + * 鎷兼帴绛惧悕瀛楃涓 + * @param array $urlObj + * + * @return 杩斿洖宸茬粡鎷兼帴濂界殑瀛楃涓 + */ + private function ToUrlParams($urlObj) + { + $buff = ""; + foreach ($urlObj as $k => $v) + { + if($k != "sign"){ + $buff .= $k . "=" . $v . "&"; + } + } + + $buff = trim($buff, "&"); + return $buff; + } + + /** + * + * 鑾峰彇鍦板潃js鍙傛暟 + * + * @return 鑾峰彇鍏变韩鏀惰揣鍦板潃js鍑芥暟闇瑕佺殑鍙傛暟锛宩son鏍煎紡鍙互鐩存帴鍋氬弬鏁颁娇鐢 + */ + public function GetEditAddressParameters() + { + $config = new WxPayConfig(); + $getData = $this->data; + $data = array(); + $data["appid"] = $config->GetAppId(); + $data["url"] = "http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']; + $time = time(); + $data["timestamp"] = "$time"; + $data["noncestr"] = WxPayApi::getNonceStr(); + $data["accesstoken"] = $getData["access_token"]; + ksort($data); + $params = $this->ToUrlParams($data); + $addrSign = sha1($params); + + $afterData = array( + "addrSign" => $addrSign, + "signType" => "sha1", + "scope" => "jsapi_address", + "appId" => $config->GetAppId(), + "timeStamp" => $data["timestamp"], + "nonceStr" => $data["noncestr"] + ); + $parameters = json_encode($afterData); + return $parameters; + } + + /** + * + * 鏋勯犺幏鍙朿ode鐨剈rl杩炴帴 + * @param string $redirectUrl 寰俊鏈嶅姟鍣ㄥ洖璺崇殑url锛岄渶瑕乽rl缂栫爜 + * + * @return 杩斿洖鏋勯犲ソ鐨剈rl + */ + private function _CreateOauthUrlForCode($redirectUrl) + { + $config = new WxPayConfig(); + $urlObj["appid"] = $config->GetAppId(); + $urlObj["redirect_uri"] = "$redirectUrl"; + $urlObj["response_type"] = "code"; + $urlObj["scope"] = "snsapi_base"; + $urlObj["state"] = "STATE"."#wechat_redirect"; + $bizString = $this->ToUrlParams($urlObj); + return "https://open.weixin.qq.com/connect/oauth2/authorize?".$bizString; + } + + /** + * + * 鏋勯犺幏鍙杘pen鍜宎ccess_toke鐨剈rl鍦板潃 + * @param string $code锛屽井淇¤烦杞甫鍥炵殑code + * + * @return 璇锋眰鐨剈rl + */ + private function __CreateOauthUrlForOpenid($code) + { + $config = new WxPayConfig(); + $urlObj["appid"] = $config->GetAppId(); + $urlObj["secret"] = $config->GetAppSecret(); + $urlObj["code"] = $code; + $urlObj["grant_type"] = "authorization_code"; + $bizString = $this->ToUrlParams($urlObj); + return "https://api.weixin.qq.com/sns/oauth2/access_token?".$bizString; + } +} diff --git a/public/php_sdk_v3.0.10/example/WxPay.MicroPay.php b/public/php_sdk_v3.0.10/example/WxPay.MicroPay.php new file mode 100755 index 0000000000000000000000000000000000000000..c359a7bb5149d2b3ca62a9309e06f8cf61cd550b --- /dev/null +++ b/public/php_sdk_v3.0.10/example/WxPay.MicroPay.php @@ -0,0 +1,166 @@ +GetOut_trade_no(); + + //鈶°佹帴鍙h皟鐢ㄦ垚鍔燂紝鏄庣‘杩斿洖璋冪敤澶辫触 + if($result["return_code"] == "SUCCESS" && + $result["result_code"] == "FAIL" && + $result["err_code"] != "USERPAYING" && + $result["err_code"] != "SYSTEMERROR") + { + return false; + } + + //鈶€佺‘璁ゆ敮浠樻槸鍚︽垚鍔 + $queryTimes = 10; + while($queryTimes > 0) + { + $succResult = 0; + $queryResult = $this->query($out_trade_no, $succResult); + //濡傛灉闇瑕佺瓑寰1s鍚庣户缁 + if($succResult == 2){ + sleep(2); + continue; + } else if($succResult == 1){//鏌ヨ鎴愬姛 + return $queryResult; + } else {//璁㈠崟浜ゆ槗澶辫触 + break; + } + } + + //鈶c佹纭澶辫触锛屽垯鎾ら攢璁㈠崟 + if(!$this->cancel($out_trade_no)) + { + throw new WxpayException("鎾ら攢鍗曞け璐ワ紒"); + } + + return false; + } + + /** + * + * 鏌ヨ璁㈠崟鎯呭喌 + * @param string $out_trade_no 鍟嗘埛璁㈠崟鍙 + * @param int $succCode 鏌ヨ璁㈠崟缁撴灉 + * @return 0 璁㈠崟涓嶆垚鍔燂紝1琛ㄧず璁㈠崟鎴愬姛锛2琛ㄧず缁х画绛夊緟 + */ + public function query($out_trade_no, &$succCode) + { + $queryOrderInput = new WxPayOrderQuery(); + $queryOrderInput->SetOut_trade_no($out_trade_no); + $config = new WxPayConfig(); + try{ + $result = WxPayApi::orderQuery($config, $queryOrderInput); + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } + if($result["return_code"] == "SUCCESS" + && $result["result_code"] == "SUCCESS") + { + //鏀粯鎴愬姛 + if($result["trade_state"] == "SUCCESS"){ + $succCode = 1; + return $result; + } + //鐢ㄦ埛鏀粯涓 + else if($result["trade_state"] == "USERPAYING"){ + $succCode = 2; + return false; + } + } + + //濡傛灉杩斿洖閿欒鐮佷负鈥滄浜ゆ槗璁㈠崟鍙蜂笉瀛樺湪鈥濆垯鐩存帴璁ゅ畾澶辫触 + if($result["err_code"] == "ORDERNOTEXIST") + { + $succCode = 0; + } else{ + //濡傛灉鏄郴缁熼敊璇紝鍒欏悗缁户缁 + $succCode = 2; + } + return false; + } + + /** + * + * 鎾ら攢璁㈠崟锛屽鏋滃け璐ヤ細閲嶅璋冪敤10娆 + * @param string $out_trade_no + * @param 璋冪敤娣卞害 $depth + */ + public function cancel($out_trade_no, $depth = 0) + { + try { + if($depth > 10){ + return false; + } + + $clostOrder = new WxPayReverse(); + $clostOrder->SetOut_trade_no($out_trade_no); + + $config = new WxPayConfig(); + $result = WxPayApi::reverse($config, $clostOrder); + + + //鎺ュ彛璋冪敤澶辫触 + if($result["return_code"] != "SUCCESS"){ + return false; + } + + //濡傛灉缁撴灉涓簊uccess涓斾笉闇瑕侀噸鏂拌皟鐢ㄦ挙閿锛屽垯琛ㄧず鎾ら攢鎴愬姛 + if($result["result_code"] != "SUCCESS" + && $result["recall"] == "N"){ + return true; + } else if($result["recall"] == "Y") { + return $this->cancel($out_trade_no, ++$depth); + } + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } + return false; + } +} \ No newline at end of file diff --git a/public/php_sdk_v3.0.10/example/WxPay.NativePay.php b/public/php_sdk_v3.0.10/example/WxPay.NativePay.php new file mode 100755 index 0000000000000000000000000000000000000000..f043bec75742fe2953c6a13351a4befea1ac1057 --- /dev/null +++ b/public/php_sdk_v3.0.10/example/WxPay.NativePay.php @@ -0,0 +1,76 @@ +SetProduct_id($productId); + try{ + $config = new WxPayConfig(); + $values = WxpayApi::bizpayurl($config, $biz); + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } + $url = "weixin://wxpay/bizpayurl?" . $this->ToUrlParams($values); + return $url; + } + + /** + * + * 鍙傛暟鏁扮粍杞崲涓簎rl鍙傛暟 + * @param array $urlObj + */ + private function ToUrlParams($urlObj) + { + $buff = ""; + foreach ($urlObj as $k => $v) + { + $buff .= $k . "=" . $v . "&"; + } + + $buff = trim($buff, "&"); + return $buff; + } + + /** + * + * 鐢熸垚鐩存帴鏀粯url锛屾敮浠榰rl鏈夋晥鏈熶负2灏忔椂,妯″紡浜 + * @param UnifiedOrderInput $input + */ + public function GetPayUrl($input) + { + if($input->GetTrade_type() == "NATIVE") + { + try{ + $config = new WxPayConfig(); + $result = WxPayApi::unifiedOrder($config, $input); + return $result; + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } + } + return false; + } +} \ No newline at end of file diff --git a/public/php_sdk_v3.0.10/example/download.php b/public/php_sdk_v3.0.10/example/download.php new file mode 100755 index 0000000000000000000000000000000000000000..7928fca381ed927937fdfe436e7db285b982d59c --- /dev/null +++ b/public/php_sdk_v3.0.10/example/download.php @@ -0,0 +1,60 @@ +SetBill_date($bill_date); + $input->SetBill_type($bill_type); + $config = new WxPayConfig(); + $file = WxPayApi::downloadBill($config, $input); + echo htmlspecialchars($file, ENT_QUOTES); + //TODO 瀵硅处鍗曟枃浠跺鐞 + exit(0); +} +?> + + + + + 寰俊鏀粯鏍蜂緥-鏌ラ娆惧崟 + + +
+
瀵硅处鏃ユ湡锛

+

+
璐﹀崟绫诲瀷锛

+

+
+ +
+
+ + diff --git a/public/php_sdk_v3.0.10/example/index.php b/public/php_sdk_v3.0.10/example/index.php new file mode 100755 index 0000000000000000000000000000000000000000..ed4c04d380e1d72213fcbfad5803c62c8a05c14e --- /dev/null +++ b/public/php_sdk_v3.0.10/example/index.php @@ -0,0 +1,68 @@ + + + + + 寰俊鏀粯鏍蜂緥 + + + +
+ +
+ + \ No newline at end of file diff --git a/public/php_sdk_v3.0.10/example/jsapi.php b/public/php_sdk_v3.0.10/example/jsapi.php new file mode 100755 index 0000000000000000000000000000000000000000..3ceba92fc4e2f325594b3d23028956aec97a4fef --- /dev/null +++ b/public/php_sdk_v3.0.10/example/jsapi.php @@ -0,0 +1,138 @@ +$value){ + echo "$key : ".htmlspecialchars($value, ENT_QUOTES)."
"; + } +} + +//鈶犮佽幏鍙栫敤鎴穙penid +try{ + + $tools = new JsApiPay(); + $openId = $tools->GetOpenid(); + + //鈶°佺粺涓涓嬪崟 + $input = new WxPayUnifiedOrder(); + $input->SetBody("test"); + $input->SetAttach("test"); + $input->SetOut_trade_no("sdkphp".date("YmdHis")); + $input->SetTotal_fee("1"); + $input->SetTime_start(date("YmdHis")); + $input->SetTime_expire(date("YmdHis", time() + 600)); + $input->SetGoods_tag("test"); + $input->SetNotify_url("http://paysdk.weixin.qq.com/notify.php"); + $input->SetTrade_type("JSAPI"); + $input->SetOpenid($openId); + $config = new WxPayConfig(); + $order = WxPayApi::unifiedOrder($config, $input); + echo '缁熶竴涓嬪崟鏀粯鍗曚俊鎭
'; + printf_info($order); + $jsApiParameters = $tools->GetJsApiParameters($order); + + //鑾峰彇鍏变韩鏀惰揣鍦板潃js鍑芥暟鍙傛暟 + $editAddress = $tools->GetEditAddressParameters(); +} catch(Exception $e) { + Log::ERROR(json_encode($e)); +} +//鈶€佸湪鏀寔鎴愬姛鍥炶皟閫氱煡涓鐞嗘垚鍔熶箣鍚庣殑浜嬪疁锛岃 notify.php +/** + * 娉ㄦ剰锛 + * 1銆佸綋浣犵殑鍥炶皟鍦板潃涓嶅彲璁块棶鐨勬椂鍊欙紝鍥炶皟閫氱煡浼氬け璐ワ紝鍙互閫氳繃鏌ヨ璁㈠崟鏉ョ‘璁ゆ敮浠樻槸鍚︽垚鍔 + * 2銆乯sapi鏀粯鏃堕渶瑕佸~鍏ョ敤鎴穙penid锛學xPay.JsApiPay.php涓湁鑾峰彇openid娴佺▼ 锛堟枃妗e彲浠ュ弬鑰冨井淇″叕浼楀钩鍙扳滅綉椤垫巿鏉冩帴鍙b濓紝 + * 鍙傝僪ttp://mp.weixin.qq.com/wiki/17/c0f37d5704f0b64713d5d2c37b468d75.html锛 + */ +?> + + + + + + 寰俊鏀粯鏍蜂緥-鏀粯 + + + + +
+ 璇ョ瑪璁㈠崟鏀粯閲戦涓1鍒

+
+ +
+ + \ No newline at end of file diff --git a/public/php_sdk_v3.0.10/example/log.php b/public/php_sdk_v3.0.10/example/log.php new file mode 100755 index 0000000000000000000000000000000000000000..379b629340a24eeca504a1e0a8f770b650af616b --- /dev/null +++ b/public/php_sdk_v3.0.10/example/log.php @@ -0,0 +1,125 @@ +handle = fopen($file,'a'); + } + + public function write($msg) + { + fwrite($this->handle, $msg, 4096); + } + + public function __destruct() + { + fclose($this->handle); + } +} + +class Log +{ + private $handler = null; + private $level = 15; + + private static $instance = null; + + private function __construct(){} + + private function __clone(){} + + public static function Init($handler = null,$level = 15) + { + if(!self::$instance instanceof self) + { + self::$instance = new self(); + self::$instance->__setHandle($handler); + self::$instance->__setLevel($level); + } + return self::$instance; + } + + + private function __setHandle($handler){ + $this->handler = $handler; + } + + private function __setLevel($level) + { + $this->level = $level; + } + + public static function DEBUG($msg) + { + self::$instance->write(1, $msg); + } + + public static function WARN($msg) + { + self::$instance->write(4, $msg); + } + + public static function ERROR($msg) + { + $debugInfo = debug_backtrace(); + $stack = "["; + foreach($debugInfo as $key => $val){ + if(array_key_exists("file", $val)){ + $stack .= ",file:" . $val["file"]; + } + if(array_key_exists("line", $val)){ + $stack .= ",line:" . $val["line"]; + } + if(array_key_exists("function", $val)){ + $stack .= ",function:" . $val["function"]; + } + } + $stack .= "]"; + self::$instance->write(8, $stack . $msg); + } + + public static function INFO($msg) + { + self::$instance->write(2, $msg); + } + + private function getLevelStr($level) + { + switch ($level) + { + case 1: + return 'debug'; + break; + case 2: + return 'info'; + break; + case 4: + return 'warn'; + break; + case 8: + return 'error'; + break; + default: + + } + } + + protected function write($level,$msg) + { + if(($level & $this->level) == $level ) + { + $msg = '['.date('Y-m-d H:i:s').']['.$this->getLevelStr($level).'] '.$msg."\n"; + $this->handler->write($msg); + } + } +} diff --git a/public/php_sdk_v3.0.10/example/micropay.php b/public/php_sdk_v3.0.10/example/micropay.php new file mode 100755 index 0000000000000000000000000000000000000000..6be7de54ca0d6194b121f0291a7f9c5966497bc8 --- /dev/null +++ b/public/php_sdk_v3.0.10/example/micropay.php @@ -0,0 +1,73 @@ + + + + + 寰俊鏀粯鏍蜂緥-鏌ラ娆惧崟 + +$value){ + echo "$key : ".htmlspecialchars($value, ENT_QUOTES)."
"; + } +} + +if(isset($_REQUEST["auth_code"]) && $_REQUEST["auth_code"] != ""){ + try { + $auth_code = $_REQUEST["auth_code"]; + $input = new WxPayMicroPay(); + $input->SetAuth_code($auth_code); + $input->SetBody("鍒峰崱娴嬭瘯鏍蜂緥-鏀粯"); + $input->SetTotal_fee("1"); + $input->SetOut_trade_no("sdkphp".date("YmdHis")); + + $microPay = new MicroPay(); + printf_info($microPay->pay($input)); + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } +} + +/** + * 娉ㄦ剰锛 + * 1銆佹彁浜よ鎵箣鍚庯紝杩斿洖绯荤粺绻佸繖銆佺敤鎴疯緭鍏ュ瘑鐮佺瓑閿欒淇℃伅鏃堕渶瑕佸惊鐜煡鍗曚互纭畾鏄惁鏀粯鎴愬姛 + * 2銆佸娆★紙涓鍗10娆★級纭閮芥湭鏄庣‘鎴愬姛鏃堕渶瑕佽皟鐢ㄦ挙鍗曟帴鍙f挙鍗曪紝闃叉鐢ㄦ埛閲嶅鏀粯 + */ + +?> + +
+
鍟嗗搧鎻忚堪锛

+

+
鏀粯閲戦锛

+

+
鎺堟潈鐮侊細

+

+
+ +
+
+ + diff --git a/public/php_sdk_v3.0.10/example/native.php b/public/php_sdk_v3.0.10/example/native.php new file mode 100755 index 0000000000000000000000000000000000000000..d50f73efe99530f4b35a5f1fd726ce7f154e6b04 --- /dev/null +++ b/public/php_sdk_v3.0.10/example/native.php @@ -0,0 +1,73 @@ +GetPrePayUrl("123456789"); + +//妯″紡浜 +/** + * 娴佺▼锛 + * 1銆佽皟鐢ㄧ粺涓涓嬪崟锛屽彇寰梒ode_url锛岀敓鎴愪簩缁寸爜 + * 2銆佺敤鎴锋壂鎻忎簩缁寸爜锛岃繘琛屾敮浠 + * 3銆佹敮浠樺畬鎴愪箣鍚庯紝寰俊鏈嶅姟鍣ㄤ細閫氱煡鏀粯鎴愬姛 + * 4銆佸湪鏀粯鎴愬姛閫氱煡涓渶瑕佹煡鍗曠‘璁ゆ槸鍚︾湡姝f敮浠樻垚鍔燂紙瑙侊細notify.php锛 + */ +$input = new WxPayUnifiedOrder(); +$input->SetBody("test"); +$input->SetAttach("test"); +$input->SetOut_trade_no("sdkphp123456789".date("YmdHis")); +$input->SetTotal_fee("1"); +$input->SetTime_start(date("YmdHis")); +$input->SetTime_expire(date("YmdHis", time() + 600)); +$input->SetGoods_tag("test"); +$input->SetNotify_url("http://paysdk.weixin.qq.com/notify.php"); +$input->SetTrade_type("NATIVE"); +$input->SetProduct_id("123456789"); + +$result = $notify->GetPayUrl($input); +$url2 = $result["code_url"]; +?> + + + + + + 寰俊鏀粯鏍蜂緥-閫娆 + + +
鎵弿鏀粯妯″紡涓

+ 妯″紡涓鎵爜鏀粯 +


+
鎵弿鏀粯妯″紡浜

+ 妯″紡浜屾壂鐮佹敮浠 +
寰俊鏀粯鏍蜂緥绋嬪簭锛屼粎鍋氬弬鑰
+ + + \ No newline at end of file diff --git a/public/php_sdk_v3.0.10/example/native_notify.php b/public/php_sdk_v3.0.10/example/native_notify.php new file mode 100755 index 0000000000000000000000000000000000000000..08a19b80e44cba545ea96cde07b5e7c9c20f1a1e --- /dev/null +++ b/public/php_sdk_v3.0.10/example/native_notify.php @@ -0,0 +1,124 @@ +SetBody("test"); + $input->SetAttach("test"); + $input->SetOut_trade_no($config->GetMerchantId().date("YmdHis")); + $input->SetTotal_fee("1"); + $input->SetTime_start(date("YmdHis")); + $input->SetTime_expire(date("YmdHis", time() + 600)); + $input->SetGoods_tag("test"); + $input->SetNotify_url("http://paysdk.weixin.qq.com/notify.php"); + $input->SetTrade_type("NATIVE"); + $input->SetOpenid($openId); + $input->SetProduct_id($product_id); + try { + $result = WxPayApi::unifiedOrder($config, $input); + Log::DEBUG("unifiedorder:" . json_encode($result)); + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } + return $result; + } + + /** + * + * 鍥炲寘鍓嶇殑鍥炶皟鏂规硶 + * 涓氬姟鍙互缁ф壙璇ユ柟娉曪紝鎵撳嵃鏃ュ織鏂逛究瀹氫綅 + * @param string $xmlData 杩斿洖鐨剎ml鍙傛暟 + * + **/ + public function LogAfterProcess($xmlData) + { + Log::DEBUG("call back锛 return xml:" . $xmlData); + return; + } + + /** + * @param WxPayNotifyResults $objData 鍥炶皟瑙i噴鍑虹殑鍙傛暟 + * @param WxPayConfigInterface $config + * @param string $msg 濡傛灉鍥炶皟澶勭悊澶辫触锛屽彲浠ュ皢閿欒淇℃伅杈撳嚭鍒拌鏂规硶 + * @return true鍥炶皟鍑烘潵瀹屾垚涓嶉渶瑕佺户缁洖璋冿紝false鍥炶皟澶勭悊鏈畬鎴愰渶瑕佺户缁洖璋 + */ + public function NotifyProcess($objData, $config, &$msg) + { + $data = $objData->GetValues(); + //echo "澶勭悊鍥炶皟"; + Log::DEBUG("call back:" . json_encode($data)); + //TODO 1銆佽繘琛屽弬鏁版牎楠 + if(!array_key_exists("openid", $data) || + !array_key_exists("product_id", $data)) + { + $msg = "鍥炶皟鏁版嵁寮傚父"; + Log::DEBUG($msg . json_encode($data)); + return false; + } + + //TODO 2銆佽繘琛岀鍚嶉獙璇 + try { + $checkResult = $objData->CheckSign($config); + if($checkResult == false){ + //绛惧悕閿欒 + Log::ERROR("绛惧悕閿欒..."); + return false; + } + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } + + $openid = $data["openid"]; + $product_id = $data["product_id"]; + + //TODO 3銆佸鐞嗕笟鍔¢昏緫 + //缁熶竴涓嬪崟 + $result = $this->unifiedorder($openid, $product_id); + if(!array_key_exists("appid", $result) || + !array_key_exists("mch_id", $result) || + !array_key_exists("prepay_id", $result)) + { + $msg = "缁熶竴涓嬪崟澶辫触"; + Log::DEBUG($msg . json_encode($data)); + return false; + } + + $this->SetData("appid", $result["appid"]); + $this->SetData("mch_id", $result["mch_id"]); + $this->SetData("nonce_str", WxPayApi::getNonceStr()); + $this->SetData("prepay_id", $result["prepay_id"]); + $this->SetData("result_code", "SUCCESS"); + $this->SetData("err_code_des", "OK"); + return true; + } +} + +$config = new WxPayConfig(); +Log::DEBUG("begin notify!"); +$notify = new NativeNotifyCallBack(); +$notify->Handle($config, true); + + + + + diff --git a/public/php_sdk_v3.0.10/example/notify.php b/public/php_sdk_v3.0.10/example/notify.php new file mode 100755 index 0000000000000000000000000000000000000000..9130603ca12344787cea7721f89f13bcebaa9450 --- /dev/null +++ b/public/php_sdk_v3.0.10/example/notify.php @@ -0,0 +1,105 @@ +SetTransaction_id($transaction_id); + + $config = new WxPayConfig(); + $result = WxPayApi::orderQuery($config, $input); + Log::DEBUG("query:" . json_encode($result)); + if(array_key_exists("return_code", $result) + && array_key_exists("result_code", $result) + && $result["return_code"] == "SUCCESS" + && $result["result_code"] == "SUCCESS") + { + return true; + } + return false; + } + + /** + * + * 鍥炲寘鍓嶇殑鍥炶皟鏂规硶 + * 涓氬姟鍙互缁ф壙璇ユ柟娉曪紝鎵撳嵃鏃ュ織鏂逛究瀹氫綅 + * @param string $xmlData 杩斿洖鐨剎ml鍙傛暟 + * + **/ + public function LogAfterProcess($xmlData) + { + Log::DEBUG("call back锛 return xml:" . $xmlData); + return; + } + + //閲嶅啓鍥炶皟澶勭悊鍑芥暟 + /** + * @param WxPayNotifyResults $data 鍥炶皟瑙i噴鍑虹殑鍙傛暟 + * @param WxPayConfigInterface $config + * @param string $msg 濡傛灉鍥炶皟澶勭悊澶辫触锛屽彲浠ュ皢閿欒淇℃伅杈撳嚭鍒拌鏂规硶 + * @return true鍥炶皟鍑烘潵瀹屾垚涓嶉渶瑕佺户缁洖璋冿紝false鍥炶皟澶勭悊鏈畬鎴愰渶瑕佺户缁洖璋 + */ + public function NotifyProcess($objData, $config, &$msg) + { + $data = $objData->GetValues(); + //TODO 1銆佽繘琛屽弬鏁版牎楠 + if(!array_key_exists("return_code", $data) + ||(array_key_exists("return_code", $data) && $data['return_code'] != "SUCCESS")) { + //TODO澶辫触,涓嶆槸鏀粯鎴愬姛鐨勯氱煡 + //濡傛灉鏈夐渶瑕佸彲浠ュ仛澶辫触鏃跺欑殑涓浜涙竻鐞嗗鐞嗭紝骞朵笖鍋氫竴浜涚洃鎺 + $msg = "寮傚父寮傚父"; + return false; + } + if(!array_key_exists("transaction_id", $data)){ + $msg = "杈撳叆鍙傛暟涓嶆纭"; + return false; + } + + //TODO 2銆佽繘琛岀鍚嶉獙璇 + try { + $checkResult = $objData->CheckSign($config); + if($checkResult == false){ + //绛惧悕閿欒 + Log::ERROR("绛惧悕閿欒..."); + return false; + } + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } + + //TODO 3銆佸鐞嗕笟鍔¢昏緫 + Log::DEBUG("call back:" . json_encode($data)); + $notfiyOutput = array(); + + + //鏌ヨ璁㈠崟锛屽垽鏂鍗曠湡瀹炴 + if(!$this->Queryorder($data["transaction_id"])){ + $msg = "璁㈠崟鏌ヨ澶辫触"; + return false; + } + return true; + } +} + +$config = new WxPayConfig(); +Log::DEBUG("begin notify"); +$notify = new PayNotifyCallBack(); +$notify->Handle($config, false); diff --git a/public/php_sdk_v3.0.10/example/orderquery.php b/public/php_sdk_v3.0.10/example/orderquery.php new file mode 100755 index 0000000000000000000000000000000000000000..cf6522b213285d4927e4585a6e9defd4220f4c2e --- /dev/null +++ b/public/php_sdk_v3.0.10/example/orderquery.php @@ -0,0 +1,77 @@ + + + + + 寰俊鏀粯鏍蜂緥-璁㈠崟鏌ヨ + +$value){ + echo "$key : ".htmlspecialchars($value, ENT_QUOTES)."
"; + } +} + + +if(isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != ""){ + try { + $transaction_id = $_REQUEST["transaction_id"]; + $input = new WxPayOrderQuery(); + $input->SetTransaction_id($transaction_id); + $config = new WxPayConfig(); + printf_info(WxPayApi::orderQuery($config, $input)); + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } + exit(); +} + +if(isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != ""){ + try{ + $out_trade_no = $_REQUEST["out_trade_no"]; + $input = new WxPayOrderQuery(); + $input->SetOut_trade_no($out_trade_no); + $config = new WxPayConfig(); + printf_info(WxPayApi::orderQuery($config, $input)); + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } + exit(); +} +?> + +
+
寰俊璁㈠崟鍙峰拰鍟嗘埛璁㈠崟鍙烽夊皯濉竴涓紝寰俊璁㈠崟鍙蜂紭鍏堬細

+
寰俊璁㈠崟鍙凤細

+

+
鍟嗘埛璁㈠崟鍙凤細

+

+
+ +
+
+ + diff --git a/public/php_sdk_v3.0.10/example/phpqrcode/phpqrcode.php b/public/php_sdk_v3.0.10/example/phpqrcode/phpqrcode.php new file mode 100755 index 0000000000000000000000000000000000000000..80adb9df239cb4cbd05cc51295f5eef5e5bbf8e7 --- /dev/null +++ b/public/php_sdk_v3.0.10/example/phpqrcode/phpqrcode.php @@ -0,0 +1,3312 @@ + + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + + +/* + * Version: 1.1.4 + * Build: 2010100721 + */ + + + +//---- qrconst.php ----------------------------- + + + + + +/* + * PHP QR Code encoder + * + * Common constants + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + // Encoding modes + + define('QR_MODE_NUL', -1); + define('QR_MODE_NUM', 0); + define('QR_MODE_AN', 1); + define('QR_MODE_8', 2); + define('QR_MODE_KANJI', 3); + define('QR_MODE_STRUCTURE', 4); + + // Levels of error correction. + + define('QR_ECLEVEL_L', 0); + define('QR_ECLEVEL_M', 1); + define('QR_ECLEVEL_Q', 2); + define('QR_ECLEVEL_H', 3); + + // Supported output formats + + define('QR_FORMAT_TEXT', 0); + define('QR_FORMAT_PNG', 1); + + class qrstr { + public static function set(&$srctab, $x, $y, $repl, $replLen = false) { + $srctab[$y] = substr_replace($srctab[$y], ($replLen !== false)?substr($repl,0,$replLen):$repl, $x, ($replLen !== false)?$replLen:strlen($repl)); + } + } + + + +//---- merged_config.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Config file, tuned-up for merged verion + */ + + define('QR_CACHEABLE', false); // use cache - more disk reads but less CPU power, masks and format templates are stored there + define('QR_CACHE_DIR', false); // used when QR_CACHEABLE === true + define('QR_LOG_DIR', false); // default error logs dir + + define('QR_FIND_BEST_MASK', true); // if true, estimates best mask (spec. default, but extremally slow; set to false to significant performance boost but (propably) worst quality code + define('QR_FIND_FROM_RANDOM', 2); // if false, checks all masks available, otherwise value tells count of masks need to be checked, mask id are got randomly + define('QR_DEFAULT_MASK', 2); // when QR_FIND_BEST_MASK === false + + define('QR_PNG_MAXIMUM_SIZE', 1024); // maximum allowed png image width (in pixels), tune to make sure GD and PHP can handle such big images + + + + +//---- qrtools.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Toolset, handy and debug utilites. + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRtools { + + //---------------------------------------------------------------------- + public static function binarize($frame) + { + $len = count($frame); + foreach ($frame as &$frameLine) { + + for($i=0; $i<$len; $i++) { + $frameLine[$i] = (ord($frameLine[$i])&1)?'1':'0'; + } + } + + return $frame; + } + + //---------------------------------------------------------------------- + public static function tcpdfBarcodeArray($code, $mode = 'QR,L', $tcPdfVersion = '4.5.037') + { + $barcode_array = array(); + + if (!is_array($mode)) + $mode = explode(',', $mode); + + $eccLevel = 'L'; + + if (count($mode) > 1) { + $eccLevel = $mode[1]; + } + + $qrTab = QRcode::text($code, false, $eccLevel); + $size = count($qrTab); + + $barcode_array['num_rows'] = $size; + $barcode_array['num_cols'] = $size; + $barcode_array['bcode'] = array(); + + foreach ($qrTab as $line) { + $arrAdd = array(); + foreach(str_split($line) as $char) + $arrAdd[] = ($char=='1')?1:0; + $barcode_array['bcode'][] = $arrAdd; + } + + return $barcode_array; + } + + //---------------------------------------------------------------------- + public static function clearCache() + { + self::$frames = array(); + } + + //---------------------------------------------------------------------- + public static function buildCache() + { + QRtools::markTime('before_build_cache'); + + $mask = new QRmask(); + for ($a=1; $a <= QRSPEC_VERSION_MAX; $a++) { + $frame = QRspec::newFrame($a); + if (QR_IMAGE) { + $fileName = QR_CACHE_DIR.'frame_'.$a.'.png'; + QRimage::png(self::binarize($frame), $fileName, 1, 0); + } + + $width = count($frame); + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); + for ($maskNo=0; $maskNo<8; $maskNo++) + $mask->makeMaskNo($maskNo, $width, $frame, $bitMask, true); + } + + QRtools::markTime('after_build_cache'); + } + + //---------------------------------------------------------------------- + public static function log($outfile, $err) + { + if (QR_LOG_DIR !== false) { + if ($err != '') { + if ($outfile !== false) { + file_put_contents(QR_LOG_DIR.basename($outfile).'-errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); + } else { + file_put_contents(QR_LOG_DIR.'errors.txt', date('Y-m-d H:i:s').': '.$err, FILE_APPEND); + } + } + } + } + + //---------------------------------------------------------------------- + public static function dumpMask($frame) + { + $width = count($frame); + for($y=0;$y<$width;$y++) { + for($x=0;$x<$width;$x++) { + echo ord($frame[$y][$x]).','; + } + } + } + + //---------------------------------------------------------------------- + public static function markTime($markerId) + { + list($usec, $sec) = explode(" ", microtime()); + $time = ((float)$usec + (float)$sec); + + if (!isset($GLOBALS['qr_time_bench'])) + $GLOBALS['qr_time_bench'] = array(); + + $GLOBALS['qr_time_bench'][$markerId] = $time; + } + + //---------------------------------------------------------------------- + public static function timeBenchmark() + { + self::markTime('finish'); + + $lastTime = 0; + $startTime = 0; + $p = 0; + + echo ' + + '; + + foreach($GLOBALS['qr_time_bench'] as $markerId=>$thisTime) { + if ($p > 0) { + echo ''; + } else { + $startTime = $thisTime; + } + + $p++; + $lastTime = $thisTime; + } + + echo ' + + +
BENCHMARK
till '.$markerId.': '.number_format($thisTime-$lastTime, 6).'s
TOTAL: '.number_format($lastTime-$startTime, 6).'s
'; + } + + } + + //########################################################################## + + QRtools::markTime('start'); + + + + +//---- qrspec.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * QR Code specifications + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * The following data / specifications are taken from + * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) + * or + * "Automatic identification and data capture techniques -- + * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('QRSPEC_VERSION_MAX', 40); + define('QRSPEC_WIDTH_MAX', 177); + + define('QRCAP_WIDTH', 0); + define('QRCAP_WORDS', 1); + define('QRCAP_REMINDER', 2); + define('QRCAP_EC', 3); + + class QRspec { + + public static $capacity = array( + array( 0, 0, 0, array( 0, 0, 0, 0)), + array( 21, 26, 0, array( 7, 10, 13, 17)), // 1 + array( 25, 44, 7, array( 10, 16, 22, 28)), + array( 29, 70, 7, array( 15, 26, 36, 44)), + array( 33, 100, 7, array( 20, 36, 52, 64)), + array( 37, 134, 7, array( 26, 48, 72, 88)), // 5 + array( 41, 172, 7, array( 36, 64, 96, 112)), + array( 45, 196, 0, array( 40, 72, 108, 130)), + array( 49, 242, 0, array( 48, 88, 132, 156)), + array( 53, 292, 0, array( 60, 110, 160, 192)), + array( 57, 346, 0, array( 72, 130, 192, 224)), //10 + array( 61, 404, 0, array( 80, 150, 224, 264)), + array( 65, 466, 0, array( 96, 176, 260, 308)), + array( 69, 532, 0, array( 104, 198, 288, 352)), + array( 73, 581, 3, array( 120, 216, 320, 384)), + array( 77, 655, 3, array( 132, 240, 360, 432)), //15 + array( 81, 733, 3, array( 144, 280, 408, 480)), + array( 85, 815, 3, array( 168, 308, 448, 532)), + array( 89, 901, 3, array( 180, 338, 504, 588)), + array( 93, 991, 3, array( 196, 364, 546, 650)), + array( 97, 1085, 3, array( 224, 416, 600, 700)), //20 + array(101, 1156, 4, array( 224, 442, 644, 750)), + array(105, 1258, 4, array( 252, 476, 690, 816)), + array(109, 1364, 4, array( 270, 504, 750, 900)), + array(113, 1474, 4, array( 300, 560, 810, 960)), + array(117, 1588, 4, array( 312, 588, 870, 1050)), //25 + array(121, 1706, 4, array( 336, 644, 952, 1110)), + array(125, 1828, 4, array( 360, 700, 1020, 1200)), + array(129, 1921, 3, array( 390, 728, 1050, 1260)), + array(133, 2051, 3, array( 420, 784, 1140, 1350)), + array(137, 2185, 3, array( 450, 812, 1200, 1440)), //30 + array(141, 2323, 3, array( 480, 868, 1290, 1530)), + array(145, 2465, 3, array( 510, 924, 1350, 1620)), + array(149, 2611, 3, array( 540, 980, 1440, 1710)), + array(153, 2761, 3, array( 570, 1036, 1530, 1800)), + array(157, 2876, 0, array( 570, 1064, 1590, 1890)), //35 + array(161, 3034, 0, array( 600, 1120, 1680, 1980)), + array(165, 3196, 0, array( 630, 1204, 1770, 2100)), + array(169, 3362, 0, array( 660, 1260, 1860, 2220)), + array(173, 3532, 0, array( 720, 1316, 1950, 2310)), + array(177, 3706, 0, array( 750, 1372, 2040, 2430)) //40 + ); + + //---------------------------------------------------------------------- + public static function getDataLength($version, $level) + { + return self::$capacity[$version][QRCAP_WORDS] - self::$capacity[$version][QRCAP_EC][$level]; + } + + //---------------------------------------------------------------------- + public static function getECCLength($version, $level) + { + return self::$capacity[$version][QRCAP_EC][$level]; + } + + //---------------------------------------------------------------------- + public static function getWidth($version) + { + return self::$capacity[$version][QRCAP_WIDTH]; + } + + //---------------------------------------------------------------------- + public static function getRemainder($version) + { + return self::$capacity[$version][QRCAP_REMINDER]; + } + + //---------------------------------------------------------------------- + public static function getMinimumVersion($size, $level) + { + + for($i=1; $i<= QRSPEC_VERSION_MAX; $i++) { + $words = self::$capacity[$i][QRCAP_WORDS] - self::$capacity[$i][QRCAP_EC][$level]; + if($words >= $size) + return $i; + } + + return -1; + } + + //###################################################################### + + public static $lengthTableBits = array( + array(10, 12, 14), + array( 9, 11, 13), + array( 8, 16, 16), + array( 8, 10, 12) + ); + + //---------------------------------------------------------------------- + public static function lengthIndicator($mode, $version) + { + if ($mode == QR_MODE_STRUCTURE) + return 0; + + if ($version <= 9) { + $l = 0; + } else if ($version <= 26) { + $l = 1; + } else { + $l = 2; + } + + return self::$lengthTableBits[$mode][$l]; + } + + //---------------------------------------------------------------------- + public static function maximumWords($mode, $version) + { + if($mode == QR_MODE_STRUCTURE) + return 3; + + if($version <= 9) { + $l = 0; + } else if($version <= 26) { + $l = 1; + } else { + $l = 2; + } + + $bits = self::$lengthTableBits[$mode][$l]; + $words = (1 << $bits) - 1; + + if($mode == QR_MODE_KANJI) { + $words *= 2; // the number of bytes is required + } + + return $words; + } + + // Error correction code ----------------------------------------------- + // Table of the error correction code (Reed-Solomon block) + // See Table 12-16 (pp.30-36), JIS X0510:2004. + + public static $eccTable = array( + array(array( 0, 0), array( 0, 0), array( 0, 0), array( 0, 0)), + array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), // 1 + array(array( 1, 0), array( 1, 0), array( 1, 0), array( 1, 0)), + array(array( 1, 0), array( 1, 0), array( 2, 0), array( 2, 0)), + array(array( 1, 0), array( 2, 0), array( 2, 0), array( 4, 0)), + array(array( 1, 0), array( 2, 0), array( 2, 2), array( 2, 2)), // 5 + array(array( 2, 0), array( 4, 0), array( 4, 0), array( 4, 0)), + array(array( 2, 0), array( 4, 0), array( 2, 4), array( 4, 1)), + array(array( 2, 0), array( 2, 2), array( 4, 2), array( 4, 2)), + array(array( 2, 0), array( 3, 2), array( 4, 4), array( 4, 4)), + array(array( 2, 2), array( 4, 1), array( 6, 2), array( 6, 2)), //10 + array(array( 4, 0), array( 1, 4), array( 4, 4), array( 3, 8)), + array(array( 2, 2), array( 6, 2), array( 4, 6), array( 7, 4)), + array(array( 4, 0), array( 8, 1), array( 8, 4), array(12, 4)), + array(array( 3, 1), array( 4, 5), array(11, 5), array(11, 5)), + array(array( 5, 1), array( 5, 5), array( 5, 7), array(11, 7)), //15 + array(array( 5, 1), array( 7, 3), array(15, 2), array( 3, 13)), + array(array( 1, 5), array(10, 1), array( 1, 15), array( 2, 17)), + array(array( 5, 1), array( 9, 4), array(17, 1), array( 2, 19)), + array(array( 3, 4), array( 3, 11), array(17, 4), array( 9, 16)), + array(array( 3, 5), array( 3, 13), array(15, 5), array(15, 10)), //20 + array(array( 4, 4), array(17, 0), array(17, 6), array(19, 6)), + array(array( 2, 7), array(17, 0), array( 7, 16), array(34, 0)), + array(array( 4, 5), array( 4, 14), array(11, 14), array(16, 14)), + array(array( 6, 4), array( 6, 14), array(11, 16), array(30, 2)), + array(array( 8, 4), array( 8, 13), array( 7, 22), array(22, 13)), //25 + array(array(10, 2), array(19, 4), array(28, 6), array(33, 4)), + array(array( 8, 4), array(22, 3), array( 8, 26), array(12, 28)), + array(array( 3, 10), array( 3, 23), array( 4, 31), array(11, 31)), + array(array( 7, 7), array(21, 7), array( 1, 37), array(19, 26)), + array(array( 5, 10), array(19, 10), array(15, 25), array(23, 25)), //30 + array(array(13, 3), array( 2, 29), array(42, 1), array(23, 28)), + array(array(17, 0), array(10, 23), array(10, 35), array(19, 35)), + array(array(17, 1), array(14, 21), array(29, 19), array(11, 46)), + array(array(13, 6), array(14, 23), array(44, 7), array(59, 1)), + array(array(12, 7), array(12, 26), array(39, 14), array(22, 41)), //35 + array(array( 6, 14), array( 6, 34), array(46, 10), array( 2, 64)), + array(array(17, 4), array(29, 14), array(49, 10), array(24, 46)), + array(array( 4, 18), array(13, 32), array(48, 14), array(42, 32)), + array(array(20, 4), array(40, 7), array(43, 22), array(10, 67)), + array(array(19, 6), array(18, 31), array(34, 34), array(20, 61)),//40 + ); + + //---------------------------------------------------------------------- + // CACHEABLE!!! + + public static function getEccSpec($version, $level, array &$spec) + { + if (count($spec) < 5) { + $spec = array(0,0,0,0,0); + } + + $b1 = self::$eccTable[$version][$level][0]; + $b2 = self::$eccTable[$version][$level][1]; + $data = self::getDataLength($version, $level); + $ecc = self::getECCLength($version, $level); + + if($b2 == 0) { + $spec[0] = $b1; + $spec[1] = (int)($data / $b1); + $spec[2] = (int)($ecc / $b1); + $spec[3] = 0; + $spec[4] = 0; + } else { + $spec[0] = $b1; + $spec[1] = (int)($data / ($b1 + $b2)); + $spec[2] = (int)($ecc / ($b1 + $b2)); + $spec[3] = $b2; + $spec[4] = $spec[1] + 1; + } + } + + // Alignment pattern --------------------------------------------------- + + // Positions of alignment patterns. + // This array includes only the second and the third position of the + // alignment patterns. Rest of them can be calculated from the distance + // between them. + + // See Table 1 in Appendix E (pp.71) of JIS X0510:2004. + + public static $alignmentPattern = array( + array( 0, 0), + array( 0, 0), array(18, 0), array(22, 0), array(26, 0), array(30, 0), // 1- 5 + array(34, 0), array(22, 38), array(24, 42), array(26, 46), array(28, 50), // 6-10 + array(30, 54), array(32, 58), array(34, 62), array(26, 46), array(26, 48), //11-15 + array(26, 50), array(30, 54), array(30, 56), array(30, 58), array(34, 62), //16-20 + array(28, 50), array(26, 50), array(30, 54), array(28, 54), array(32, 58), //21-25 + array(30, 58), array(34, 62), array(26, 50), array(30, 54), array(26, 52), //26-30 + array(30, 56), array(34, 60), array(30, 58), array(34, 62), array(30, 54), //31-35 + array(24, 50), array(28, 54), array(32, 58), array(26, 54), array(30, 58), //35-40 + ); + + + /** -------------------------------------------------------------------- + * Put an alignment marker. + * @param frame + * @param width + * @param ox,oy center coordinate of the pattern + */ + public static function putAlignmentMarker(array &$frame, $ox, $oy) + { + $finder = array( + "\xa1\xa1\xa1\xa1\xa1", + "\xa1\xa0\xa0\xa0\xa1", + "\xa1\xa0\xa1\xa0\xa1", + "\xa1\xa0\xa0\xa0\xa1", + "\xa1\xa1\xa1\xa1\xa1" + ); + + $yStart = $oy-2; + $xStart = $ox-2; + + for($y=0; $y<5; $y++) { + QRstr::set($frame, $xStart, $yStart+$y, $finder[$y]); + } + } + + //---------------------------------------------------------------------- + public static function putAlignmentPattern($version, &$frame, $width) + { + if($version < 2) + return; + + $d = self::$alignmentPattern[$version][1] - self::$alignmentPattern[$version][0]; + if($d < 0) { + $w = 2; + } else { + $w = (int)(($width - self::$alignmentPattern[$version][0]) / $d + 2); + } + + if($w * $w - 3 == 1) { + $x = self::$alignmentPattern[$version][0]; + $y = self::$alignmentPattern[$version][0]; + self::putAlignmentMarker($frame, $x, $y); + return; + } + + $cx = self::$alignmentPattern[$version][0]; + for($x=1; $x<$w - 1; $x++) { + self::putAlignmentMarker($frame, 6, $cx); + self::putAlignmentMarker($frame, $cx, 6); + $cx += $d; + } + + $cy = self::$alignmentPattern[$version][0]; + for($y=0; $y<$w-1; $y++) { + $cx = self::$alignmentPattern[$version][0]; + for($x=0; $x<$w-1; $x++) { + self::putAlignmentMarker($frame, $cx, $cy); + $cx += $d; + } + $cy += $d; + } + } + + // Version information pattern ----------------------------------------- + + // Version information pattern (BCH coded). + // See Table 1 in Appendix D (pp.68) of JIS X0510:2004. + + // size: [QRSPEC_VERSION_MAX - 6] + + public static $versionPattern = array( + 0x07c94, 0x085bc, 0x09a99, 0x0a4d3, 0x0bbf6, 0x0c762, 0x0d847, 0x0e60d, + 0x0f928, 0x10b78, 0x1145d, 0x12a17, 0x13532, 0x149a6, 0x15683, 0x168c9, + 0x177ec, 0x18ec4, 0x191e1, 0x1afab, 0x1b08e, 0x1cc1a, 0x1d33f, 0x1ed75, + 0x1f250, 0x209d5, 0x216f0, 0x228ba, 0x2379f, 0x24b0b, 0x2542e, 0x26a64, + 0x27541, 0x28c69 + ); + + //---------------------------------------------------------------------- + public static function getVersionPattern($version) + { + if($version < 7 || $version > QRSPEC_VERSION_MAX) + return 0; + + return self::$versionPattern[$version -7]; + } + + // Format information -------------------------------------------------- + // See calcFormatInfo in tests/test_qrspec.c (orginal qrencode c lib) + + public static $formatInfo = array( + array(0x77c4, 0x72f3, 0x7daa, 0x789d, 0x662f, 0x6318, 0x6c41, 0x6976), + array(0x5412, 0x5125, 0x5e7c, 0x5b4b, 0x45f9, 0x40ce, 0x4f97, 0x4aa0), + array(0x355f, 0x3068, 0x3f31, 0x3a06, 0x24b4, 0x2183, 0x2eda, 0x2bed), + array(0x1689, 0x13be, 0x1ce7, 0x19d0, 0x0762, 0x0255, 0x0d0c, 0x083b) + ); + + public static function getFormatInfo($mask, $level) + { + if($mask < 0 || $mask > 7) + return 0; + + if($level < 0 || $level > 3) + return 0; + + return self::$formatInfo[$level][$mask]; + } + + // Frame --------------------------------------------------------------- + // Cache of initial frames. + + public static $frames = array(); + + /** -------------------------------------------------------------------- + * Put a finder pattern. + * @param frame + * @param width + * @param ox,oy upper-left coordinate of the pattern + */ + public static function putFinderPattern(&$frame, $ox, $oy) + { + $finder = array( + "\xc1\xc1\xc1\xc1\xc1\xc1\xc1", + "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", + "\xc1\xc0\xc1\xc1\xc1\xc0\xc1", + "\xc1\xc0\xc0\xc0\xc0\xc0\xc1", + "\xc1\xc1\xc1\xc1\xc1\xc1\xc1" + ); + + for($y=0; $y<7; $y++) { + QRstr::set($frame, $ox, $oy+$y, $finder[$y]); + } + } + + //---------------------------------------------------------------------- + public static function createFrame($version) + { + $width = self::$capacity[$version][QRCAP_WIDTH]; + $frameLine = str_repeat ("\0", $width); + $frame = array_fill(0, $width, $frameLine); + + // Finder pattern + self::putFinderPattern($frame, 0, 0); + self::putFinderPattern($frame, $width - 7, 0); + self::putFinderPattern($frame, 0, $width - 7); + + // Separator + $yOffset = $width - 7; + + for($y=0; $y<7; $y++) { + $frame[$y][7] = "\xc0"; + $frame[$y][$width - 8] = "\xc0"; + $frame[$yOffset][7] = "\xc0"; + $yOffset++; + } + + $setPattern = str_repeat("\xc0", 8); + + QRstr::set($frame, 0, 7, $setPattern); + QRstr::set($frame, $width-8, 7, $setPattern); + QRstr::set($frame, 0, $width - 8, $setPattern); + + // Format info + $setPattern = str_repeat("\x84", 9); + QRstr::set($frame, 0, 8, $setPattern); + QRstr::set($frame, $width - 8, 8, $setPattern, 8); + + $yOffset = $width - 8; + + for($y=0; $y<8; $y++,$yOffset++) { + $frame[$y][8] = "\x84"; + $frame[$yOffset][8] = "\x84"; + } + + // Timing pattern + + for($i=1; $i<$width-15; $i++) { + $frame[6][7+$i] = chr(0x90 | ($i & 1)); + $frame[7+$i][6] = chr(0x90 | ($i & 1)); + } + + // Alignment pattern + self::putAlignmentPattern($version, $frame, $width); + + // Version information + if($version >= 7) { + $vinf = self::getVersionPattern($version); + + $v = $vinf; + + for($x=0; $x<6; $x++) { + for($y=0; $y<3; $y++) { + $frame[($width - 11)+$y][$x] = chr(0x88 | ($v & 1)); + $v = $v >> 1; + } + } + + $v = $vinf; + for($y=0; $y<6; $y++) { + for($x=0; $x<3; $x++) { + $frame[$y][$x+($width - 11)] = chr(0x88 | ($v & 1)); + $v = $v >> 1; + } + } + } + + // and a little bit... + $frame[$width - 8][8] = "\x81"; + + return $frame; + } + + //---------------------------------------------------------------------- + public static function debug($frame, $binary_mode = false) + { + if ($binary_mode) { + + foreach ($frame as &$frameLine) { + $frameLine = join('  ', explode('0', $frameLine)); + $frameLine = join('██', explode('1', $frameLine)); + } + + ?> + +


        '; + echo join("
        ", $frame); + echo '






'; + + } else { + + foreach ($frame as &$frameLine) { + $frameLine = join(' ', explode("\xc0", $frameLine)); + $frameLine = join('', explode("\xc1", $frameLine)); + $frameLine = join(' ', explode("\xa0", $frameLine)); + $frameLine = join('', explode("\xa1", $frameLine)); + $frameLine = join('', explode("\x84", $frameLine)); //format 0 + $frameLine = join('', explode("\x85", $frameLine)); //format 1 + $frameLine = join('', explode("\x81", $frameLine)); //special bit + $frameLine = join(' ', explode("\x90", $frameLine)); //clock 0 + $frameLine = join('', explode("\x91", $frameLine)); //clock 1 + $frameLine = join(' ', explode("\x88", $frameLine)); //version + $frameLine = join('', explode("\x89", $frameLine)); //version + $frameLine = join('♦', explode("\x01", $frameLine)); + $frameLine = join('⋅', explode("\0", $frameLine)); + } + + ?> + + "; + echo join("
", $frame); + echo "
"; + + } + } + + //---------------------------------------------------------------------- + public static function serial($frame) + { + return gzcompress(join("\n", $frame), 9); + } + + //---------------------------------------------------------------------- + public static function unserial($code) + { + return explode("\n", gzuncompress($code)); + } + + //---------------------------------------------------------------------- + public static function newFrame($version) + { + if($version < 1 || $version > QRSPEC_VERSION_MAX) + return null; + + if(!isset(self::$frames[$version])) { + + $fileName = QR_CACHE_DIR.'frame_'.$version.'.dat'; + + if (QR_CACHEABLE) { + if (file_exists($fileName)) { + self::$frames[$version] = self::unserial(file_get_contents($fileName)); + } else { + self::$frames[$version] = self::createFrame($version); + file_put_contents($fileName, self::serial(self::$frames[$version])); + } + } else { + self::$frames[$version] = self::createFrame($version); + } + } + + if(is_null(self::$frames[$version])) + return null; + + return self::$frames[$version]; + } + + //---------------------------------------------------------------------- + public static function rsBlockNum($spec) { return $spec[0] + $spec[3]; } + public static function rsBlockNum1($spec) { return $spec[0]; } + public static function rsDataCodes1($spec) { return $spec[1]; } + public static function rsEccCodes1($spec) { return $spec[2]; } + public static function rsBlockNum2($spec) { return $spec[3]; } + public static function rsDataCodes2($spec) { return $spec[4]; } + public static function rsEccCodes2($spec) { return $spec[2]; } + public static function rsDataLength($spec) { return ($spec[0] * $spec[1]) + ($spec[3] * $spec[4]); } + public static function rsEccLength($spec) { return ($spec[0] + $spec[3]) * $spec[2]; } + + } + + + +//---- qrimage.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Image output of code using GD2 + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('QR_IMAGE', true); + + class QRimage { + + //---------------------------------------------------------------------- + public static function png($frame, $filename = false, $pixelPerPoint = 4, $outerFrame = 4,$saveandprint=FALSE) + { + $image = self::image($frame, $pixelPerPoint, $outerFrame); + + if ($filename === false) { + Header("Content-type: image/png"); + ImagePng($image); + } else { + if($saveandprint===TRUE){ + ImagePng($image, $filename); + header("Content-type: image/png"); + ImagePng($image); + }else{ + ImagePng($image, $filename); + } + } + + ImageDestroy($image); + } + + //---------------------------------------------------------------------- + public static function jpg($frame, $filename = false, $pixelPerPoint = 8, $outerFrame = 4, $q = 85) + { + $image = self::image($frame, $pixelPerPoint, $outerFrame); + + if ($filename === false) { + Header("Content-type: image/jpeg"); + ImageJpeg($image, null, $q); + } else { + ImageJpeg($image, $filename, $q); + } + + ImageDestroy($image); + } + + //---------------------------------------------------------------------- + private static function image($frame, $pixelPerPoint = 4, $outerFrame = 4) + { + $h = count($frame); + $w = strlen($frame[0]); + + $imgW = $w + 2*$outerFrame; + $imgH = $h + 2*$outerFrame; + + $base_image =ImageCreate($imgW, $imgH); + + $col[0] = ImageColorAllocate($base_image,255,255,255); + $col[1] = ImageColorAllocate($base_image,0,0,0); + + imagefill($base_image, 0, 0, $col[0]); + + for($y=0; $y<$h; $y++) { + for($x=0; $x<$w; $x++) { + if ($frame[$y][$x] == '1') { + ImageSetPixel($base_image,$x+$outerFrame,$y+$outerFrame,$col[1]); + } + } + } + + $target_image =ImageCreate($imgW * $pixelPerPoint, $imgH * $pixelPerPoint); + ImageCopyResized($target_image, $base_image, 0, 0, 0, 0, $imgW * $pixelPerPoint, $imgH * $pixelPerPoint, $imgW, $imgH); + ImageDestroy($base_image); + + return $target_image; + } + } + + + +//---- qrinput.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Input encoding class + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('STRUCTURE_HEADER_BITS', 20); + define('MAX_STRUCTURED_SYMBOLS', 16); + + class QRinputItem { + + public $mode; + public $size; + public $data; + public $bstream; + + public function __construct($mode, $size, $data, $bstream = null) + { + $setData = array_slice($data, 0, $size); + + if (count($setData) < $size) { + $setData = array_merge($setData, array_fill(0,$size-count($setData),0)); + } + + if(!QRinput::check($mode, $size, $setData)) { + throw new Exception('Error m:'.$mode.',s:'.$size.',d:'.join(',',$setData)); + return null; + } + + $this->mode = $mode; + $this->size = $size; + $this->data = $setData; + $this->bstream = $bstream; + } + + //---------------------------------------------------------------------- + public function encodeModeNum($version) + { + try { + + $words = (int)($this->size / 3); + $bs = new QRbitstream(); + + $val = 0x1; + $bs->appendNum(4, $val); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_NUM, $version), $this->size); + + for($i=0; $i<$words; $i++) { + $val = (ord($this->data[$i*3 ]) - ord('0')) * 100; + $val += (ord($this->data[$i*3+1]) - ord('0')) * 10; + $val += (ord($this->data[$i*3+2]) - ord('0')); + $bs->appendNum(10, $val); + } + + if($this->size - $words * 3 == 1) { + $val = ord($this->data[$words*3]) - ord('0'); + $bs->appendNum(4, $val); + } else if($this->size - $words * 3 == 2) { + $val = (ord($this->data[$words*3 ]) - ord('0')) * 10; + $val += (ord($this->data[$words*3+1]) - ord('0')); + $bs->appendNum(7, $val); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeModeAn($version) + { + try { + $words = (int)($this->size / 2); + $bs = new QRbitstream(); + + $bs->appendNum(4, 0x02); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_AN, $version), $this->size); + + for($i=0; $i<$words; $i++) { + $val = (int)QRinput::lookAnTable(ord($this->data[$i*2 ])) * 45; + $val += (int)QRinput::lookAnTable(ord($this->data[$i*2+1])); + + $bs->appendNum(11, $val); + } + + if($this->size & 1) { + $val = QRinput::lookAnTable(ord($this->data[$words * 2])); + $bs->appendNum(6, $val); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeMode8($version) + { + try { + $bs = new QRbitstream(); + + $bs->appendNum(4, 0x4); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_8, $version), $this->size); + + for($i=0; $i<$this->size; $i++) { + $bs->appendNum(8, ord($this->data[$i])); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeModeKanji($version) + { + try { + + $bs = new QRbitrtream(); + + $bs->appendNum(4, 0x8); + $bs->appendNum(QRspec::lengthIndicator(QR_MODE_KANJI, $version), (int)($this->size / 2)); + + for($i=0; $i<$this->size; $i+=2) { + $val = (ord($this->data[$i]) << 8) | ord($this->data[$i+1]); + if($val <= 0x9ffc) { + $val -= 0x8140; + } else { + $val -= 0xc140; + } + + $h = ($val >> 8) * 0xc0; + $val = ($val & 0xff) + $h; + + $bs->appendNum(13, $val); + } + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function encodeModeStructure() + { + try { + $bs = new QRbitstream(); + + $bs->appendNum(4, 0x03); + $bs->appendNum(4, ord($this->data[1]) - 1); + $bs->appendNum(4, ord($this->data[0]) - 1); + $bs->appendNum(8, ord($this->data[2])); + + $this->bstream = $bs; + return 0; + + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function estimateBitStreamSizeOfEntry($version) + { + $bits = 0; + + if($version == 0) + $version = 1; + + switch($this->mode) { + case QR_MODE_NUM: $bits = QRinput::estimateBitsModeNum($this->size); break; + case QR_MODE_AN: $bits = QRinput::estimateBitsModeAn($this->size); break; + case QR_MODE_8: $bits = QRinput::estimateBitsMode8($this->size); break; + case QR_MODE_KANJI: $bits = QRinput::estimateBitsModeKanji($this->size);break; + case QR_MODE_STRUCTURE: return STRUCTURE_HEADER_BITS; + default: + return 0; + } + + $l = QRspec::lengthIndicator($this->mode, $version); + $m = 1 << $l; + $num = (int)(($this->size + $m - 1) / $m); + + $bits += $num * (4 + $l); + + return $bits; + } + + //---------------------------------------------------------------------- + public function encodeBitStream($version) + { + try { + + unset($this->bstream); + $words = QRspec::maximumWords($this->mode, $version); + + if($this->size > $words) { + + $st1 = new QRinputItem($this->mode, $words, $this->data); + $st2 = new QRinputItem($this->mode, $this->size - $words, array_slice($this->data, $words)); + + $st1->encodeBitStream($version); + $st2->encodeBitStream($version); + + $this->bstream = new QRbitstream(); + $this->bstream->append($st1->bstream); + $this->bstream->append($st2->bstream); + + unset($st1); + unset($st2); + + } else { + + $ret = 0; + + switch($this->mode) { + case QR_MODE_NUM: $ret = $this->encodeModeNum($version); break; + case QR_MODE_AN: $ret = $this->encodeModeAn($version); break; + case QR_MODE_8: $ret = $this->encodeMode8($version); break; + case QR_MODE_KANJI: $ret = $this->encodeModeKanji($version);break; + case QR_MODE_STRUCTURE: $ret = $this->encodeModeStructure(); break; + + default: + break; + } + + if($ret < 0) + return -1; + } + + return $this->bstream->size(); + + } catch (Exception $e) { + return -1; + } + } + }; + + //########################################################################## + + class QRinput { + + public $items; + + private $version; + private $level; + + //---------------------------------------------------------------------- + public function __construct($version = 0, $level = QR_ECLEVEL_L) + { + if ($version < 0 || $version > QRSPEC_VERSION_MAX || $level > QR_ECLEVEL_H) { + throw new Exception('Invalid version no'); + return NULL; + } + + $this->version = $version; + $this->level = $level; + } + + //---------------------------------------------------------------------- + public function getVersion() + { + return $this->version; + } + + //---------------------------------------------------------------------- + public function setVersion($version) + { + if($version < 0 || $version > QRSPEC_VERSION_MAX) { + throw new Exception('Invalid version no'); + return -1; + } + + $this->version = $version; + + return 0; + } + + //---------------------------------------------------------------------- + public function getErrorCorrectionLevel() + { + return $this->level; + } + + //---------------------------------------------------------------------- + public function setErrorCorrectionLevel($level) + { + if($level > QR_ECLEVEL_H) { + throw new Exception('Invalid ECLEVEL'); + return -1; + } + + $this->level = $level; + + return 0; + } + + //---------------------------------------------------------------------- + public function appendEntry(QRinputItem $entry) + { + $this->items[] = $entry; + } + + //---------------------------------------------------------------------- + public function append($mode, $size, $data) + { + try { + $entry = new QRinputItem($mode, $size, $data); + $this->items[] = $entry; + return 0; + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + + public function insertStructuredAppendHeader($size, $index, $parity) + { + if( $size > MAX_STRUCTURED_SYMBOLS ) { + throw new Exception('insertStructuredAppendHeader wrong size'); + } + + if( $index <= 0 || $index > MAX_STRUCTURED_SYMBOLS ) { + throw new Exception('insertStructuredAppendHeader wrong index'); + } + + $buf = array($size, $index, $parity); + + try { + $entry = new QRinputItem(QR_MODE_STRUCTURE, 3, buf); + array_unshift($this->items, $entry); + return 0; + } catch (Exception $e) { + return -1; + } + } + + //---------------------------------------------------------------------- + public function calcParity() + { + $parity = 0; + + foreach($this->items as $item) { + if($item->mode != QR_MODE_STRUCTURE) { + for($i=$item->size-1; $i>=0; $i--) { + $parity ^= $item->data[$i]; + } + } + } + + return $parity; + } + + //---------------------------------------------------------------------- + public static function checkModeNum($size, $data) + { + for($i=0; $i<$size; $i++) { + if((ord($data[$i]) < ord('0')) || (ord($data[$i]) > ord('9'))){ + return false; + } + } + + return true; + } + + //---------------------------------------------------------------------- + public static function estimateBitsModeNum($size) + { + $w = (int)$size / 3; + $bits = $w * 10; + + switch($size - $w * 3) { + case 1: + $bits += 4; + break; + case 2: + $bits += 7; + break; + default: + break; + } + + return $bits; + } + + //---------------------------------------------------------------------- + public static $anTable = array( + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + 36, -1, -1, -1, 37, 38, -1, -1, -1, -1, 39, 40, -1, 41, 42, 43, + 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 44, -1, -1, -1, -1, -1, + -1, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, + 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 + ); + + //---------------------------------------------------------------------- + public static function lookAnTable($c) + { + return (($c > 127)?-1:self::$anTable[$c]); + } + + //---------------------------------------------------------------------- + public static function checkModeAn($size, $data) + { + for($i=0; $i<$size; $i++) { + if (self::lookAnTable(ord($data[$i])) == -1) { + return false; + } + } + + return true; + } + + //---------------------------------------------------------------------- + public static function estimateBitsModeAn($size) + { + $w = (int)($size / 2); + $bits = $w * 11; + + if($size & 1) { + $bits += 6; + } + + return $bits; + } + + //---------------------------------------------------------------------- + public static function estimateBitsMode8($size) + { + return $size * 8; + } + + //---------------------------------------------------------------------- + public function estimateBitsModeKanji($size) + { + return (int)(($size / 2) * 13); + } + + //---------------------------------------------------------------------- + public static function checkModeKanji($size, $data) + { + if($size & 1) + return false; + + for($i=0; $i<$size; $i+=2) { + $val = (ord($data[$i]) << 8) | ord($data[$i+1]); + if( $val < 0x8140 + || ($val > 0x9ffc && $val < 0xe040) + || $val > 0xebbf) { + return false; + } + } + + return true; + } + + /*********************************************************************** + * Validation + **********************************************************************/ + + public static function check($mode, $size, $data) + { + if($size <= 0) + return false; + + switch($mode) { + case QR_MODE_NUM: return self::checkModeNum($size, $data); break; + case QR_MODE_AN: return self::checkModeAn($size, $data); break; + case QR_MODE_KANJI: return self::checkModeKanji($size, $data); break; + case QR_MODE_8: return true; break; + case QR_MODE_STRUCTURE: return true; break; + + default: + break; + } + + return false; + } + + + //---------------------------------------------------------------------- + public function estimateBitStreamSize($version) + { + $bits = 0; + + foreach($this->items as $item) { + $bits += $item->estimateBitStreamSizeOfEntry($version); + } + + return $bits; + } + + //---------------------------------------------------------------------- + public function estimateVersion() + { + $version = 0; + $prev = 0; + do { + $prev = $version; + $bits = $this->estimateBitStreamSize($prev); + $version = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); + if ($version < 0) { + return -1; + } + } while ($version > $prev); + + return $version; + } + + //---------------------------------------------------------------------- + public static function lengthOfCode($mode, $version, $bits) + { + $payload = $bits - 4 - QRspec::lengthIndicator($mode, $version); + switch($mode) { + case QR_MODE_NUM: + $chunks = (int)($payload / 10); + $remain = $payload - $chunks * 10; + $size = $chunks * 3; + if($remain >= 7) { + $size += 2; + } else if($remain >= 4) { + $size += 1; + } + break; + case QR_MODE_AN: + $chunks = (int)($payload / 11); + $remain = $payload - $chunks * 11; + $size = $chunks * 2; + if($remain >= 6) + $size++; + break; + case QR_MODE_8: + $size = (int)($payload / 8); + break; + case QR_MODE_KANJI: + $size = (int)(($payload / 13) * 2); + break; + case QR_MODE_STRUCTURE: + $size = (int)($payload / 8); + break; + default: + $size = 0; + break; + } + + $maxsize = QRspec::maximumWords($mode, $version); + if($size < 0) $size = 0; + if($size > $maxsize) $size = $maxsize; + + return $size; + } + + //---------------------------------------------------------------------- + public function createBitStream() + { + $total = 0; + + foreach($this->items as $item) { + $bits = $item->encodeBitStream($this->version); + + if($bits < 0) + return -1; + + $total += $bits; + } + + return $total; + } + + //---------------------------------------------------------------------- + public function convertData() + { + $ver = $this->estimateVersion(); + if($ver > $this->getVersion()) { + $this->setVersion($ver); + } + + for(;;) { + $bits = $this->createBitStream(); + + if($bits < 0) + return -1; + + $ver = QRspec::getMinimumVersion((int)(($bits + 7) / 8), $this->level); + if($ver < 0) { + throw new Exception('WRONG VERSION'); + return -1; + } else if($ver > $this->getVersion()) { + $this->setVersion($ver); + } else { + break; + } + } + + return 0; + } + + //---------------------------------------------------------------------- + public function appendPaddingBit(&$bstream) + { + $bits = $bstream->size(); + $maxwords = QRspec::getDataLength($this->version, $this->level); + $maxbits = $maxwords * 8; + + if ($maxbits == $bits) { + return 0; + } + + if ($maxbits - $bits < 5) { + return $bstream->appendNum($maxbits - $bits, 0); + } + + $bits += 4; + $words = (int)(($bits + 7) / 8); + + $padding = new QRbitstream(); + $ret = $padding->appendNum($words * 8 - $bits + 4, 0); + + if($ret < 0) + return $ret; + + $padlen = $maxwords - $words; + + if($padlen > 0) { + + $padbuf = array(); + for($i=0; $i<$padlen; $i++) { + $padbuf[$i] = ($i&1)?0x11:0xec; + } + + $ret = $padding->appendBytes($padlen, $padbuf); + + if($ret < 0) + return $ret; + + } + + $ret = $bstream->append($padding); + + return $ret; + } + + //---------------------------------------------------------------------- + public function mergeBitStream() + { + if($this->convertData() < 0) { + return null; + } + + $bstream = new QRbitstream(); + + foreach($this->items as $item) { + $ret = $bstream->append($item->bstream); + if($ret < 0) { + return null; + } + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public function getBitStream() + { + + $bstream = $this->mergeBitStream(); + + if($bstream == null) { + return null; + } + + $ret = $this->appendPaddingBit($bstream); + if($ret < 0) { + return null; + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public function getByteStream() + { + $bstream = $this->getBitStream(); + if($bstream == null) { + return null; + } + + return $bstream->toByte(); + } + } + + + + + + +//---- qrbitstream.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Bitstream class + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRbitstream { + + public $data = array(); + + //---------------------------------------------------------------------- + public function size() + { + return count($this->data); + } + + //---------------------------------------------------------------------- + public function allocate($setLength) + { + $this->data = array_fill(0, $setLength, 0); + return 0; + } + + //---------------------------------------------------------------------- + public static function newFromNum($bits, $num) + { + $bstream = new QRbitstream(); + $bstream->allocate($bits); + + $mask = 1 << ($bits - 1); + for($i=0; $i<$bits; $i++) { + if($num & $mask) { + $bstream->data[$i] = 1; + } else { + $bstream->data[$i] = 0; + } + $mask = $mask >> 1; + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public static function newFromBytes($size, $data) + { + $bstream = new QRbitstream(); + $bstream->allocate($size * 8); + $p=0; + + for($i=0; $i<$size; $i++) { + $mask = 0x80; + for($j=0; $j<8; $j++) { + if($data[$i] & $mask) { + $bstream->data[$p] = 1; + } else { + $bstream->data[$p] = 0; + } + $p++; + $mask = $mask >> 1; + } + } + + return $bstream; + } + + //---------------------------------------------------------------------- + public function append(QRbitstream $arg) + { + if (is_null($arg)) { + return -1; + } + + if($arg->size() == 0) { + return 0; + } + + if($this->size() == 0) { + $this->data = $arg->data; + return 0; + } + + $this->data = array_values(array_merge($this->data, $arg->data)); + + return 0; + } + + //---------------------------------------------------------------------- + public function appendNum($bits, $num) + { + if ($bits == 0) + return 0; + + $b = QRbitstream::newFromNum($bits, $num); + + if(is_null($b)) + return -1; + + $ret = $this->append($b); + unset($b); + + return $ret; + } + + //---------------------------------------------------------------------- + public function appendBytes($size, $data) + { + if ($size == 0) + return 0; + + $b = QRbitstream::newFromBytes($size, $data); + + if(is_null($b)) + return -1; + + $ret = $this->append($b); + unset($b); + + return $ret; + } + + //---------------------------------------------------------------------- + public function toByte() + { + + $size = $this->size(); + + if($size == 0) { + return array(); + } + + $data = array_fill(0, (int)(($size + 7) / 8), 0); + $bytes = (int)($size / 8); + + $p = 0; + + for($i=0; $i<$bytes; $i++) { + $v = 0; + for($j=0; $j<8; $j++) { + $v = $v << 1; + $v |= $this->data[$p]; + $p++; + } + $data[$i] = $v; + } + + if($size & 7) { + $v = 0; + for($j=0; $j<($size & 7); $j++) { + $v = $v << 1; + $v |= $this->data[$p]; + $p++; + } + $data[$bytes] = $v; + } + + return $data; + } + + } + + + + +//---- qrsplit.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Input splitting classes + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * The following data / specifications are taken from + * "Two dimensional symbol -- QR-code -- Basic Specification" (JIS X0510:2004) + * or + * "Automatic identification and data capture techniques -- + * QR Code 2005 bar code symbology specification" (ISO/IEC 18004:2006) + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + class QRsplit { + + public $dataStr = ''; + public $input; + public $modeHint; + + //---------------------------------------------------------------------- + public function __construct($dataStr, $input, $modeHint) + { + $this->dataStr = $dataStr; + $this->input = $input; + $this->modeHint = $modeHint; + } + + //---------------------------------------------------------------------- + public static function isdigitat($str, $pos) + { + if ($pos >= strlen($str)) + return false; + + return ((ord($str[$pos]) >= ord('0'))&&(ord($str[$pos]) <= ord('9'))); + } + + //---------------------------------------------------------------------- + public static function isalnumat($str, $pos) + { + if ($pos >= strlen($str)) + return false; + + return (QRinput::lookAnTable(ord($str[$pos])) >= 0); + } + + //---------------------------------------------------------------------- + public function identifyMode($pos) + { + if ($pos >= strlen($this->dataStr)) + return QR_MODE_NUL; + + $c = $this->dataStr[$pos]; + + if(self::isdigitat($this->dataStr, $pos)) { + return QR_MODE_NUM; + } else if(self::isalnumat($this->dataStr, $pos)) { + return QR_MODE_AN; + } else if($this->modeHint == QR_MODE_KANJI) { + + if ($pos+1 < strlen($this->dataStr)) + { + $d = $this->dataStr[$pos+1]; + $word = (ord($c) << 8) | ord($d); + if(($word >= 0x8140 && $word <= 0x9ffc) || ($word >= 0xe040 && $word <= 0xebbf)) { + return QR_MODE_KANJI; + } + } + } + + return QR_MODE_8; + } + + //---------------------------------------------------------------------- + public function eatNum() + { + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); + + $p = 0; + while(self::isdigitat($this->dataStr, $p)) { + $p++; + } + + $run = $p; + $mode = $this->identifyMode($p); + + if($mode == QR_MODE_8) { + $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln + + QRinput::estimateBitsMode8(1) // + 4 + l8 + - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 + if($dif > 0) { + return $this->eat8(); + } + } + if($mode == QR_MODE_AN) { + $dif = QRinput::estimateBitsModeNum($run) + 4 + $ln + + QRinput::estimateBitsModeAn(1) // + 4 + la + - QRinput::estimateBitsModeAn($run + 1);// - 4 - la + if($dif > 0) { + return $this->eatAn(); + } + } + + $ret = $this->input->append(QR_MODE_NUM, $run, str_split($this->dataStr)); + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function eatAn() + { + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); + + $p = 0; + + while(self::isalnumat($this->dataStr, $p)) { + if(self::isdigitat($this->dataStr, $p)) { + $q = $p; + while(self::isdigitat($this->dataStr, $q)) { + $q++; + } + + $dif = QRinput::estimateBitsModeAn($p) // + 4 + la + + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln + - QRinput::estimateBitsModeAn($q); // - 4 - la + + if($dif < 0) { + break; + } else { + $p = $q; + } + } else { + $p++; + } + } + + $run = $p; + + if(!self::isalnumat($this->dataStr, $p)) { + $dif = QRinput::estimateBitsModeAn($run) + 4 + $la + + QRinput::estimateBitsMode8(1) // + 4 + l8 + - QRinput::estimateBitsMode8($run + 1); // - 4 - l8 + if($dif > 0) { + return $this->eat8(); + } + } + + $ret = $this->input->append(QR_MODE_AN, $run, str_split($this->dataStr)); + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function eatKanji() + { + $p = 0; + + while($this->identifyMode($p) == QR_MODE_KANJI) { + $p += 2; + } + + $ret = $this->input->append(QR_MODE_KANJI, $p, str_split($this->dataStr)); + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function eat8() + { + $la = QRspec::lengthIndicator(QR_MODE_AN, $this->input->getVersion()); + $ln = QRspec::lengthIndicator(QR_MODE_NUM, $this->input->getVersion()); + + $p = 1; + $dataStrLen = strlen($this->dataStr); + + while($p < $dataStrLen) { + + $mode = $this->identifyMode($p); + if($mode == QR_MODE_KANJI) { + break; + } + if($mode == QR_MODE_NUM) { + $q = $p; + while(self::isdigitat($this->dataStr, $q)) { + $q++; + } + $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 + + QRinput::estimateBitsModeNum($q - $p) + 4 + $ln + - QRinput::estimateBitsMode8($q); // - 4 - l8 + if($dif < 0) { + break; + } else { + $p = $q; + } + } else if($mode == QR_MODE_AN) { + $q = $p; + while(self::isalnumat($this->dataStr, $q)) { + $q++; + } + $dif = QRinput::estimateBitsMode8($p) // + 4 + l8 + + QRinput::estimateBitsModeAn($q - $p) + 4 + $la + - QRinput::estimateBitsMode8($q); // - 4 - l8 + if($dif < 0) { + break; + } else { + $p = $q; + } + } else { + $p++; + } + } + + $run = $p; + $ret = $this->input->append(QR_MODE_8, $run, str_split($this->dataStr)); + + if($ret < 0) + return -1; + + return $run; + } + + //---------------------------------------------------------------------- + public function splitString() + { + while (strlen($this->dataStr) > 0) + { + if($this->dataStr == '') + return 0; + + $mode = $this->identifyMode(0); + + switch ($mode) { + case QR_MODE_NUM: $length = $this->eatNum(); break; + case QR_MODE_AN: $length = $this->eatAn(); break; + case QR_MODE_KANJI: + if ($hint == QR_MODE_KANJI) + $length = $this->eatKanji(); + else $length = $this->eat8(); + break; + default: $length = $this->eat8(); break; + + } + + if($length == 0) return 0; + if($length < 0) return -1; + + $this->dataStr = substr($this->dataStr, $length); + } + } + + //---------------------------------------------------------------------- + public function toUpper() + { + $stringLen = strlen($this->dataStr); + $p = 0; + + while ($p<$stringLen) { + $mode = self::identifyMode(substr($this->dataStr, $p), $this->modeHint); + if($mode == QR_MODE_KANJI) { + $p += 2; + } else { + if (ord($this->dataStr[$p]) >= ord('a') && ord($this->dataStr[$p]) <= ord('z')) { + $this->dataStr[$p] = chr(ord($this->dataStr[$p]) - 32); + } + $p++; + } + } + + return $this->dataStr; + } + + //---------------------------------------------------------------------- + public static function splitStringToQRinput($string, QRinput $input, $modeHint, $casesensitive = true) + { + if(is_null($string) || $string == '\0' || $string == '') { + throw new Exception('empty string!!!'); + } + + $split = new QRsplit($string, $input, $modeHint); + + if(!$casesensitive) + $split->toUpper(); + + return $split->splitString(); + } + } + + + +//---- qrrscode.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Reed-Solomon error correction support + * + * Copyright (C) 2002, 2003, 2004, 2006 Phil Karn, KA9Q + * (libfec is released under the GNU Lesser General Public License.) + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRrsItem { + + public $mm; // Bits per symbol + public $nn; // Symbols per block (= (1<= $this->nn) { + $x -= $this->nn; + $x = ($x >> $this->mm) + ($x & $this->nn); + } + + return $x; + } + + //---------------------------------------------------------------------- + public static function init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) + { + // Common code for intializing a Reed-Solomon control block (char or int symbols) + // Copyright 2004 Phil Karn, KA9Q + // May be used under the terms of the GNU Lesser General Public License (LGPL) + + $rs = null; + + // Check parameter ranges + if($symsize < 0 || $symsize > 8) return $rs; + if($fcr < 0 || $fcr >= (1<<$symsize)) return $rs; + if($prim <= 0 || $prim >= (1<<$symsize)) return $rs; + if($nroots < 0 || $nroots >= (1<<$symsize)) return $rs; // Can't have more roots than symbol values! + if($pad < 0 || $pad >= ((1<<$symsize) -1 - $nroots)) return $rs; // Too much padding + + $rs = new QRrsItem(); + $rs->mm = $symsize; + $rs->nn = (1<<$symsize)-1; + $rs->pad = $pad; + + $rs->alpha_to = array_fill(0, $rs->nn+1, 0); + $rs->index_of = array_fill(0, $rs->nn+1, 0); + + // PHP style macro replacement ;) + $NN =& $rs->nn; + $A0 =& $NN; + + // Generate Galois field lookup tables + $rs->index_of[0] = $A0; // log(zero) = -inf + $rs->alpha_to[$A0] = 0; // alpha**-inf = 0 + $sr = 1; + + for($i=0; $i<$rs->nn; $i++) { + $rs->index_of[$sr] = $i; + $rs->alpha_to[$i] = $sr; + $sr <<= 1; + if($sr & (1<<$symsize)) { + $sr ^= $gfpoly; + } + $sr &= $rs->nn; + } + + if($sr != 1){ + // field generator polynomial is not primitive! + $rs = NULL; + return $rs; + } + + /* Form RS code generator polynomial from its roots */ + $rs->genpoly = array_fill(0, $nroots+1, 0); + + $rs->fcr = $fcr; + $rs->prim = $prim; + $rs->nroots = $nroots; + $rs->gfpoly = $gfpoly; + + /* Find prim-th root of 1, used in decoding */ + for($iprim=1;($iprim % $prim) != 0;$iprim += $rs->nn) + ; // intentional empty-body loop! + + $rs->iprim = (int)($iprim / $prim); + $rs->genpoly[0] = 1; + + for ($i = 0,$root=$fcr*$prim; $i < $nroots; $i++, $root += $prim) { + $rs->genpoly[$i+1] = 1; + + // Multiply rs->genpoly[] by @**(root + x) + for ($j = $i; $j > 0; $j--) { + if ($rs->genpoly[$j] != 0) { + $rs->genpoly[$j] = $rs->genpoly[$j-1] ^ $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[$j]] + $root)]; + } else { + $rs->genpoly[$j] = $rs->genpoly[$j-1]; + } + } + // rs->genpoly[0] can never be zero + $rs->genpoly[0] = $rs->alpha_to[$rs->modnn($rs->index_of[$rs->genpoly[0]] + $root)]; + } + + // convert rs->genpoly[] to index form for quicker encoding + for ($i = 0; $i <= $nroots; $i++) + $rs->genpoly[$i] = $rs->index_of[$rs->genpoly[$i]]; + + return $rs; + } + + //---------------------------------------------------------------------- + public function encode_rs_char($data, &$parity) + { + $MM =& $this->mm; + $NN =& $this->nn; + $ALPHA_TO =& $this->alpha_to; + $INDEX_OF =& $this->index_of; + $GENPOLY =& $this->genpoly; + $NROOTS =& $this->nroots; + $FCR =& $this->fcr; + $PRIM =& $this->prim; + $IPRIM =& $this->iprim; + $PAD =& $this->pad; + $A0 =& $NN; + + $parity = array_fill(0, $NROOTS, 0); + + for($i=0; $i< ($NN-$NROOTS-$PAD); $i++) { + + $feedback = $INDEX_OF[$data[$i] ^ $parity[0]]; + if($feedback != $A0) { + // feedback term is non-zero + + // This line is unnecessary when GENPOLY[NROOTS] is unity, as it must + // always be for the polynomials constructed by init_rs() + $feedback = $this->modnn($NN - $GENPOLY[$NROOTS] + $feedback); + + for($j=1;$j<$NROOTS;$j++) { + $parity[$j] ^= $ALPHA_TO[$this->modnn($feedback + $GENPOLY[$NROOTS-$j])]; + } + } + + // Shift + array_shift($parity); + if($feedback != $A0) { + array_push($parity, $ALPHA_TO[$this->modnn($feedback + $GENPOLY[0])]); + } else { + array_push($parity, 0); + } + } + } + } + + //########################################################################## + + class QRrs { + + public static $items = array(); + + //---------------------------------------------------------------------- + public static function init_rs($symsize, $gfpoly, $fcr, $prim, $nroots, $pad) + { + foreach(self::$items as $rs) { + if($rs->pad != $pad) continue; + if($rs->nroots != $nroots) continue; + if($rs->mm != $symsize) continue; + if($rs->gfpoly != $gfpoly) continue; + if($rs->fcr != $fcr) continue; + if($rs->prim != $prim) continue; + + return $rs; + } + + $rs = QRrsItem::init_rs_char($symsize, $gfpoly, $fcr, $prim, $nroots, $pad); + array_unshift(self::$items, $rs); + + return $rs; + } + } + + + +//---- qrmask.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Masking + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + define('N1', 3); + define('N2', 3); + define('N3', 40); + define('N4', 10); + + class QRmask { + + public $runLength = array(); + + //---------------------------------------------------------------------- + public function __construct() + { + $this->runLength = array_fill(0, QRSPEC_WIDTH_MAX + 1, 0); + } + + //---------------------------------------------------------------------- + public function writeFormatInformation($width, &$frame, $mask, $level) + { + $blacks = 0; + $format = QRspec::getFormatInfo($mask, $level); + + for($i=0; $i<8; $i++) { + if($format & 1) { + $blacks += 2; + $v = 0x85; + } else { + $v = 0x84; + } + + $frame[8][$width - 1 - $i] = chr($v); + if($i < 6) { + $frame[$i][8] = chr($v); + } else { + $frame[$i + 1][8] = chr($v); + } + $format = $format >> 1; + } + + for($i=0; $i<7; $i++) { + if($format & 1) { + $blacks += 2; + $v = 0x85; + } else { + $v = 0x84; + } + + $frame[$width - 7 + $i][8] = chr($v); + if($i == 0) { + $frame[8][7] = chr($v); + } else { + $frame[8][6 - $i] = chr($v); + } + + $format = $format >> 1; + } + + return $blacks; + } + + //---------------------------------------------------------------------- + public function mask0($x, $y) { return ($x+$y)&1; } + public function mask1($x, $y) { return ($y&1); } + public function mask2($x, $y) { return ($x%3); } + public function mask3($x, $y) { return ($x+$y)%3; } + public function mask4($x, $y) { return (((int)($y/2))+((int)($x/3)))&1; } + public function mask5($x, $y) { return (($x*$y)&1)+($x*$y)%3; } + public function mask6($x, $y) { return ((($x*$y)&1)+($x*$y)%3)&1; } + public function mask7($x, $y) { return ((($x*$y)%3)+(($x+$y)&1))&1; } + + //---------------------------------------------------------------------- + private function generateMaskNo($maskNo, $width, $frame) + { + $bitMask = array_fill(0, $width, array_fill(0, $width, 0)); + + for($y=0; $y<$width; $y++) { + for($x=0; $x<$width; $x++) { + if(ord($frame[$y][$x]) & 0x80) { + $bitMask[$y][$x] = 0; + } else { + $maskFunc = call_user_func(array($this, 'mask'.$maskNo), $x, $y); + $bitMask[$y][$x] = ($maskFunc == 0)?1:0; + } + + } + } + + return $bitMask; + } + + //---------------------------------------------------------------------- + public static function serial($bitFrame) + { + $codeArr = array(); + + foreach ($bitFrame as $line) + $codeArr[] = join('', $line); + + return gzcompress(join("\n", $codeArr), 9); + } + + //---------------------------------------------------------------------- + public static function unserial($code) + { + $codeArr = array(); + + $codeLines = explode("\n", gzuncompress($code)); + foreach ($codeLines as $line) + $codeArr[] = str_split($line); + + return $codeArr; + } + + //---------------------------------------------------------------------- + public function makeMaskNo($maskNo, $width, $s, &$d, $maskGenOnly = false) + { + $b = 0; + $bitMask = array(); + + $fileName = QR_CACHE_DIR.'mask_'.$maskNo.DIRECTORY_SEPARATOR.'mask_'.$width.'_'.$maskNo.'.dat'; + + if (QR_CACHEABLE) { + if (file_exists($fileName)) { + $bitMask = self::unserial(file_get_contents($fileName)); + } else { + $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); + if (!file_exists(QR_CACHE_DIR.'mask_'.$maskNo)) + mkdir(QR_CACHE_DIR.'mask_'.$maskNo); + file_put_contents($fileName, self::serial($bitMask)); + } + } else { + $bitMask = $this->generateMaskNo($maskNo, $width, $s, $d); + } + + if ($maskGenOnly) + return; + + $d = $s; + + for($y=0; $y<$width; $y++) { + for($x=0; $x<$width; $x++) { + if($bitMask[$y][$x] == 1) { + $d[$y][$x] = chr(ord($s[$y][$x]) ^ (int)$bitMask[$y][$x]); + } + $b += (int)(ord($d[$y][$x]) & 1); + } + } + + return $b; + } + + //---------------------------------------------------------------------- + public function makeMask($width, $frame, $maskNo, $level) + { + $masked = array_fill(0, $width, str_repeat("\0", $width)); + $this->makeMaskNo($maskNo, $width, $frame, $masked); + $this->writeFormatInformation($width, $masked, $maskNo, $level); + + return $masked; + } + + //---------------------------------------------------------------------- + public function calcN1N3($length) + { + $demerit = 0; + + for($i=0; $i<$length; $i++) { + + if($this->runLength[$i] >= 5) { + $demerit += (N1 + ($this->runLength[$i] - 5)); + } + if($i & 1) { + if(($i >= 3) && ($i < ($length-2)) && ($this->runLength[$i] % 3 == 0)) { + $fact = (int)($this->runLength[$i] / 3); + if(($this->runLength[$i-2] == $fact) && + ($this->runLength[$i-1] == $fact) && + ($this->runLength[$i+1] == $fact) && + ($this->runLength[$i+2] == $fact)) { + if(($this->runLength[$i-3] < 0) || ($this->runLength[$i-3] >= (4 * $fact))) { + $demerit += N3; + } else if((($i+3) >= $length) || ($this->runLength[$i+3] >= (4 * $fact))) { + $demerit += N3; + } + } + } + } + } + return $demerit; + } + + //---------------------------------------------------------------------- + public function evaluateSymbol($width, $frame) + { + $head = 0; + $demerit = 0; + + for($y=0; $y<$width; $y++) { + $head = 0; + $this->runLength[0] = 1; + + $frameY = $frame[$y]; + + if ($y>0) + $frameYM = $frame[$y-1]; + + for($x=0; $x<$width; $x++) { + if(($x > 0) && ($y > 0)) { + $b22 = ord($frameY[$x]) & ord($frameY[$x-1]) & ord($frameYM[$x]) & ord($frameYM[$x-1]); + $w22 = ord($frameY[$x]) | ord($frameY[$x-1]) | ord($frameYM[$x]) | ord($frameYM[$x-1]); + + if(($b22 | ($w22 ^ 1))&1) { + $demerit += N2; + } + } + if(($x == 0) && (ord($frameY[$x]) & 1)) { + $this->runLength[0] = -1; + $head = 1; + $this->runLength[$head] = 1; + } else if($x > 0) { + if((ord($frameY[$x]) ^ ord($frameY[$x-1])) & 1) { + $head++; + $this->runLength[$head] = 1; + } else { + $this->runLength[$head]++; + } + } + } + + $demerit += $this->calcN1N3($head+1); + } + + for($x=0; $x<$width; $x++) { + $head = 0; + $this->runLength[0] = 1; + + for($y=0; $y<$width; $y++) { + if($y == 0 && (ord($frame[$y][$x]) & 1)) { + $this->runLength[0] = -1; + $head = 1; + $this->runLength[$head] = 1; + } else if($y > 0) { + if((ord($frame[$y][$x]) ^ ord($frame[$y-1][$x])) & 1) { + $head++; + $this->runLength[$head] = 1; + } else { + $this->runLength[$head]++; + } + } + } + + $demerit += $this->calcN1N3($head+1); + } + + return $demerit; + } + + + //---------------------------------------------------------------------- + public function mask($width, $frame, $level) + { + $minDemerit = PHP_INT_MAX; + $bestMaskNum = 0; + $bestMask = array(); + + $checked_masks = array(0,1,2,3,4,5,6,7); + + if (QR_FIND_FROM_RANDOM !== false) { + + $howManuOut = 8-(QR_FIND_FROM_RANDOM % 9); + for ($i = 0; $i < $howManuOut; $i++) { + $remPos = rand (0, count($checked_masks)-1); + unset($checked_masks[$remPos]); + $checked_masks = array_values($checked_masks); + } + + } + + $bestMask = $frame; + + foreach($checked_masks as $i) { + $mask = array_fill(0, $width, str_repeat("\0", $width)); + + $demerit = 0; + $blacks = 0; + $blacks = $this->makeMaskNo($i, $width, $frame, $mask); + $blacks += $this->writeFormatInformation($width, $mask, $i, $level); + $blacks = (int)(100 * $blacks / ($width * $width)); + $demerit = (int)((int)(abs($blacks - 50) / 5) * N4); + $demerit += $this->evaluateSymbol($width, $mask); + + if($demerit < $minDemerit) { + $minDemerit = $demerit; + $bestMask = $mask; + $bestMaskNum = $i; + } + } + + return $bestMask; + } + + //---------------------------------------------------------------------- + } + + + + +//---- qrencode.php ----------------------------- + + + + +/* + * PHP QR Code encoder + * + * Main encoder classes. + * + * Based on libqrencode C library distributed under LGPL 2.1 + * Copyright (C) 2006, 2007, 2008, 2009 Kentaro Fukuchi + * + * PHP QR Code is distributed under LGPL 3 + * Copyright (C) 2010 Dominik Dzienia + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + + class QRrsblock { + public $dataLength; + public $data = array(); + public $eccLength; + public $ecc = array(); + + public function __construct($dl, $data, $el, &$ecc, QRrsItem $rs) + { + $rs->encode_rs_char($data, $ecc); + + $this->dataLength = $dl; + $this->data = $data; + $this->eccLength = $el; + $this->ecc = $ecc; + } + }; + + //########################################################################## + + class QRrawcode { + public $version; + public $datacode = array(); + public $ecccode = array(); + public $blocks; + public $rsblocks = array(); //of RSblock + public $count; + public $dataLength; + public $eccLength; + public $b1; + + //---------------------------------------------------------------------- + public function __construct(QRinput $input) + { + $spec = array(0,0,0,0,0); + + $this->datacode = $input->getByteStream(); + if(is_null($this->datacode)) { + throw new Exception('null imput string'); + } + + QRspec::getEccSpec($input->getVersion(), $input->getErrorCorrectionLevel(), $spec); + + $this->version = $input->getVersion(); + $this->b1 = QRspec::rsBlockNum1($spec); + $this->dataLength = QRspec::rsDataLength($spec); + $this->eccLength = QRspec::rsEccLength($spec); + $this->ecccode = array_fill(0, $this->eccLength, 0); + $this->blocks = QRspec::rsBlockNum($spec); + + $ret = $this->init($spec); + if($ret < 0) { + throw new Exception('block alloc error'); + return null; + } + + $this->count = 0; + } + + //---------------------------------------------------------------------- + public function init(array $spec) + { + $dl = QRspec::rsDataCodes1($spec); + $el = QRspec::rsEccCodes1($spec); + $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); + + + $blockNo = 0; + $dataPos = 0; + $eccPos = 0; + for($i=0; $iecccode,$eccPos); + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); + $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); + + $dataPos += $dl; + $eccPos += $el; + $blockNo++; + } + + if(QRspec::rsBlockNum2($spec) == 0) + return 0; + + $dl = QRspec::rsDataCodes2($spec); + $el = QRspec::rsEccCodes2($spec); + $rs = QRrs::init_rs(8, 0x11d, 0, 1, $el, 255 - $dl - $el); + + if($rs == NULL) return -1; + + for($i=0; $iecccode,$eccPos); + $this->rsblocks[$blockNo] = new QRrsblock($dl, array_slice($this->datacode, $dataPos), $el, $ecc, $rs); + $this->ecccode = array_merge(array_slice($this->ecccode,0, $eccPos), $ecc); + + $dataPos += $dl; + $eccPos += $el; + $blockNo++; + } + + return 0; + } + + //---------------------------------------------------------------------- + public function getCode() + { + $ret; + + if($this->count < $this->dataLength) { + $row = $this->count % $this->blocks; + $col = $this->count / $this->blocks; + if($col >= $this->rsblocks[0]->dataLength) { + $row += $this->b1; + } + $ret = $this->rsblocks[$row]->data[$col]; + } else if($this->count < $this->dataLength + $this->eccLength) { + $row = ($this->count - $this->dataLength) % $this->blocks; + $col = ($this->count - $this->dataLength) / $this->blocks; + $ret = $this->rsblocks[$row]->ecc[$col]; + } else { + return 0; + } + $this->count++; + + return $ret; + } + } + + //########################################################################## + + class QRcode { + + public $version; + public $width; + public $data; + + //---------------------------------------------------------------------- + public function encodeMask(QRinput $input, $mask) + { + if($input->getVersion() < 0 || $input->getVersion() > QRSPEC_VERSION_MAX) { + throw new Exception('wrong version'); + } + if($input->getErrorCorrectionLevel() > QR_ECLEVEL_H) { + throw new Exception('wrong level'); + } + + $raw = new QRrawcode($input); + + QRtools::markTime('after_raw'); + + $version = $raw->version; + $width = QRspec::getWidth($version); + $frame = QRspec::newFrame($version); + + $filler = new FrameFiller($width, $frame); + if(is_null($filler)) { + return NULL; + } + + // inteleaved data and ecc codes + for($i=0; $i<$raw->dataLength + $raw->eccLength; $i++) { + $code = $raw->getCode(); + $bit = 0x80; + for($j=0; $j<8; $j++) { + $addr = $filler->next(); + $filler->setFrameAt($addr, 0x02 | (($bit & $code) != 0)); + $bit = $bit >> 1; + } + } + + QRtools::markTime('after_filler'); + + unset($raw); + + // remainder bits + $j = QRspec::getRemainder($version); + for($i=0; $i<$j; $i++) { + $addr = $filler->next(); + $filler->setFrameAt($addr, 0x02); + } + + $frame = $filler->frame; + unset($filler); + + + // masking + $maskObj = new QRmask(); + if($mask < 0) { + + if (QR_FIND_BEST_MASK) { + $masked = $maskObj->mask($width, $frame, $input->getErrorCorrectionLevel()); + } else { + $masked = $maskObj->makeMask($width, $frame, (intval(QR_DEFAULT_MASK) % 8), $input->getErrorCorrectionLevel()); + } + } else { + $masked = $maskObj->makeMask($width, $frame, $mask, $input->getErrorCorrectionLevel()); + } + + if($masked == NULL) { + return NULL; + } + + QRtools::markTime('after_mask'); + + $this->version = $version; + $this->width = $width; + $this->data = $masked; + + return $this; + } + + //---------------------------------------------------------------------- + public function encodeInput(QRinput $input) + { + return $this->encodeMask($input, -1); + } + + //---------------------------------------------------------------------- + public function encodeString8bit($string, $version, $level) + { + if(string == NULL) { + throw new Exception('empty string!'); + return NULL; + } + + $input = new QRinput($version, $level); + if($input == NULL) return NULL; + + $ret = $input->append($input, QR_MODE_8, strlen($string), str_split($string)); + if($ret < 0) { + unset($input); + return NULL; + } + return $this->encodeInput($input); + } + + //---------------------------------------------------------------------- + public function encodeString($string, $version, $level, $hint, $casesensitive) + { + + if($hint != QR_MODE_8 && $hint != QR_MODE_KANJI) { + throw new Exception('bad hint'); + return NULL; + } + + $input = new QRinput($version, $level); + if($input == NULL) return NULL; + + $ret = QRsplit::splitStringToQRinput($string, $input, $hint, $casesensitive); + if($ret < 0) { + return NULL; + } + + return $this->encodeInput($input); + } + + //---------------------------------------------------------------------- + public static function png($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4, $saveandprint=false) + { + $enc = QRencode::factory($level, $size, $margin); + return $enc->encodePNG($text, $outfile, $saveandprint=false); + } + + //---------------------------------------------------------------------- + public static function text($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) + { + $enc = QRencode::factory($level, $size, $margin); + return $enc->encode($text, $outfile); + } + + //---------------------------------------------------------------------- + public static function raw($text, $outfile = false, $level = QR_ECLEVEL_L, $size = 3, $margin = 4) + { + $enc = QRencode::factory($level, $size, $margin); + return $enc->encodeRAW($text, $outfile); + } + } + + //########################################################################## + + class FrameFiller { + + public $width; + public $frame; + public $x; + public $y; + public $dir; + public $bit; + + //---------------------------------------------------------------------- + public function __construct($width, &$frame) + { + $this->width = $width; + $this->frame = $frame; + $this->x = $width - 1; + $this->y = $width - 1; + $this->dir = -1; + $this->bit = -1; + } + + //---------------------------------------------------------------------- + public function setFrameAt($at, $val) + { + $this->frame[$at['y']][$at['x']] = chr($val); + } + + //---------------------------------------------------------------------- + public function getFrameAt($at) + { + return ord($this->frame[$at['y']][$at['x']]); + } + + //---------------------------------------------------------------------- + public function next() + { + do { + + if($this->bit == -1) { + $this->bit = 0; + return array('x'=>$this->x, 'y'=>$this->y); + } + + $x = $this->x; + $y = $this->y; + $w = $this->width; + + if($this->bit == 0) { + $x--; + $this->bit++; + } else { + $x++; + $y += $this->dir; + $this->bit--; + } + + if($this->dir < 0) { + if($y < 0) { + $y = 0; + $x -= 2; + $this->dir = 1; + if($x == 6) { + $x--; + $y = 9; + } + } + } else { + if($y == $w) { + $y = $w - 1; + $x -= 2; + $this->dir = -1; + if($x == 6) { + $x--; + $y -= 8; + } + } + } + if($x < 0 || $y < 0) return null; + + $this->x = $x; + $this->y = $y; + + } while(ord($this->frame[$y][$x]) & 0x80); + + return array('x'=>$x, 'y'=>$y); + } + + } ; + + //########################################################################## + + class QRencode { + + public $casesensitive = true; + public $eightbit = false; + + public $version = 0; + public $size = 3; + public $margin = 4; + + public $structured = 0; // not supported yet + + public $level = QR_ECLEVEL_L; + public $hint = QR_MODE_8; + + //---------------------------------------------------------------------- + public static function factory($level = QR_ECLEVEL_L, $size = 3, $margin = 4) + { + $enc = new QRencode(); + $enc->size = $size; + $enc->margin = $margin; + + switch ($level.'') { + case '0': + case '1': + case '2': + case '3': + $enc->level = $level; + break; + case 'l': + case 'L': + $enc->level = QR_ECLEVEL_L; + break; + case 'm': + case 'M': + $enc->level = QR_ECLEVEL_M; + break; + case 'q': + case 'Q': + $enc->level = QR_ECLEVEL_Q; + break; + case 'h': + case 'H': + $enc->level = QR_ECLEVEL_H; + break; + } + + return $enc; + } + + //---------------------------------------------------------------------- + public function encodeRAW($intext, $outfile = false) + { + $code = new QRcode(); + + if($this->eightbit) { + $code->encodeString8bit($intext, $this->version, $this->level); + } else { + $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); + } + + return $code->data; + } + + //---------------------------------------------------------------------- + public function encode($intext, $outfile = false) + { + $code = new QRcode(); + + if($this->eightbit) { + $code->encodeString8bit($intext, $this->version, $this->level); + } else { + $code->encodeString($intext, $this->version, $this->level, $this->hint, $this->casesensitive); + } + + QRtools::markTime('after_encode'); + + if ($outfile!== false) { + file_put_contents($outfile, join("\n", QRtools::binarize($code->data))); + } else { + return QRtools::binarize($code->data); + } + } + + //---------------------------------------------------------------------- + public function encodePNG($intext, $outfile = false,$saveandprint=false) + { + try { + + ob_start(); + $tab = $this->encode($intext); + $err = ob_get_contents(); + ob_end_clean(); + + if ($err != '') + QRtools::log($outfile, $err); + + $maxSize = (int)(QR_PNG_MAXIMUM_SIZE / (count($tab)+2*$this->margin)); + + QRimage::png($tab, $outfile, min(max(1, $this->size), $maxSize), $this->margin,$saveandprint); + + } catch (Exception $e) { + + QRtools::log($outfile, $e->getMessage()); + + } + } + } + + diff --git a/public/php_sdk_v3.0.10/example/qrcode.php b/public/php_sdk_v3.0.10/example/qrcode.php new file mode 100755 index 0000000000000000000000000000000000000000..226da398a0fb0ba98e23d19f55d43d80df60229e --- /dev/null +++ b/public/php_sdk_v3.0.10/example/qrcode.php @@ -0,0 +1,15 @@ + + + + + 寰俊鏀粯鏍蜂緥-閫娆 + +$value){ + echo "$key : ".htmlspecialchars($value, ENT_QUOTES)."
"; + } +} + +if(isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != ""){ + try{ + $transaction_id = $_REQUEST["transaction_id"]; + $total_fee = $_REQUEST["total_fee"]; + $refund_fee = $_REQUEST["refund_fee"]; + $input = new WxPayRefund(); + $input->SetTransaction_id($transaction_id); + $input->SetTotal_fee($total_fee); + $input->SetRefund_fee($refund_fee); + + $config = new WxPayConfig(); + $input->SetOut_refund_no("sdkphp".date("YmdHis")); + $input->SetOp_user_id($config->GetMerchantId()); + printf_info(WxPayApi::refund($config, $input)); + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } + exit(); +} + +//$_REQUEST["out_trade_no"]= "122531270220150304194108"; +///$_REQUEST["total_fee"]= "1"; +//$_REQUEST["refund_fee"] = "1"; +if(isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != ""){ + try{ + $out_trade_no = $_REQUEST["out_trade_no"]; + $total_fee = $_REQUEST["total_fee"]; + $refund_fee = $_REQUEST["refund_fee"]; + $input = new WxPayRefund(); + $input->SetOut_trade_no($out_trade_no); + $input->SetTotal_fee($total_fee); + $input->SetRefund_fee($refund_fee); + + $config = new WxPayConfig(); + $input->SetOut_refund_no("sdkphp".date("YmdHis")); + $input->SetOp_user_id($config->GetMerchantId()); + printf_info(WxPayApi::refund($config, $input)); + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } + exit(); +} +?> + +
+
寰俊璁㈠崟鍙峰拰鍟嗘埛璁㈠崟鍙烽夊皯濉竴涓紝寰俊璁㈠崟鍙蜂紭鍏堬細

+
寰俊璁㈠崟鍙凤細

+

+
鍟嗘埛璁㈠崟鍙凤細

+

+
璁㈠崟鎬婚噾棰(鍒)锛

+

+
閫娆鹃噾棰(鍒)锛

+

+
+ +
+
+ + diff --git a/public/php_sdk_v3.0.10/example/refundquery.php b/public/php_sdk_v3.0.10/example/refundquery.php new file mode 100755 index 0000000000000000000000000000000000000000..edea154684367980d3e4010cde4d7f17c0dfbb50 --- /dev/null +++ b/public/php_sdk_v3.0.10/example/refundquery.php @@ -0,0 +1,112 @@ + + + + + 寰俊鏀粯鏍蜂緥-鏌ラ娆惧崟 + +$value){ + echo "$key : ".htmlspecialchars($value, ENT_QUOTES)."
"; + } +} + +if(isset($_REQUEST["transaction_id"]) && $_REQUEST["transaction_id"] != ""){ + try{ + $transaction_id = $_REQUEST["transaction_id"]; + $input = new WxPayRefundQuery(); + $input->SetTransaction_id($transaction_id); + $config = new WxPayConfig(); + printf_info(WxPayApi::refundQuery($config, $input)); + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } +} + +if(isset($_REQUEST["out_trade_no"]) && $_REQUEST["out_trade_no"] != ""){ + try{ + $out_trade_no = $_REQUEST["out_trade_no"]; + $input = new WxPayRefundQuery(); + $input->SetOut_trade_no($out_trade_no); + $config = new WxPayConfig(); + printf_info(WxPayApi::refundQuery($config, $input)); + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } + exit(); +} + +if(isset($_REQUEST["out_refund_no"]) && $_REQUEST["out_refund_no"] != ""){ + try{ + $out_refund_no = $_REQUEST["out_refund_no"]; + $input = new WxPayRefundQuery(); + $input->SetOut_refund_no($out_refund_no); + $config = new WxPayConfig(); + printf_info(WxPayApi::refundQuery($config, $input)); + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } + exit(); +} + +if(isset($_REQUEST["refund_id"]) && $_REQUEST["refund_id"] != ""){ + try{ + $refund_id = $_REQUEST["refund_id"]; + $input = new WxPayRefundQuery(); + $input->SetRefund_id($refund_id); + $config = new WxPayConfig(); + printf_info(WxPayApi::refundQuery($config, $input)); + } catch(Exception $e) { + Log::ERROR(json_encode($e)); + } + exit(); +} + +?> + +
+
寰俊璁㈠崟鍙枫佸晢鎴疯鍗曞彿銆佸井淇¤鍗曞彿銆佸井淇¢娆惧崟鍙烽夊~鑷冲皯涓涓紝寰俊閫娆惧崟鍙蜂紭鍏堬細

+
寰俊璁㈠崟鍙凤細

+

+
鍟嗘埛璁㈠崟鍙凤細

+

+
鍟嗘埛閫娆惧崟鍙凤細

+

+
寰俊閫娆惧崟鍙凤細

+

+
+ +
+
+ + diff --git a/public/php_sdk_v3.0.10/lib/WxPay.Api.php b/public/php_sdk_v3.0.10/lib/WxPay.Api.php new file mode 100755 index 0000000000000000000000000000000000000000..ad5b1870fd214eeff982e0c718c667c82756982c --- /dev/null +++ b/public/php_sdk_v3.0.10/lib/WxPay.Api.php @@ -0,0 +1,616 @@ +IsOut_trade_noSet()) { + throw new WxPayException("缂哄皯缁熶竴鏀粯鎺ュ彛蹇呭~鍙傛暟out_trade_no锛"); + }else if(!$inputObj->IsBodySet()){ + throw new WxPayException("缂哄皯缁熶竴鏀粯鎺ュ彛蹇呭~鍙傛暟body锛"); + }else if(!$inputObj->IsTotal_feeSet()) { + throw new WxPayException("缂哄皯缁熶竴鏀粯鎺ュ彛蹇呭~鍙傛暟total_fee锛"); + }else if(!$inputObj->IsTrade_typeSet()) { + throw new WxPayException("缂哄皯缁熶竴鏀粯鎺ュ彛蹇呭~鍙傛暟trade_type锛"); + } + + //鍏宠仈鍙傛暟 + if($inputObj->GetTrade_type() == "JSAPI" && !$inputObj->IsOpenidSet()){ + throw new WxPayException("缁熶竴鏀粯鎺ュ彛涓紝缂哄皯蹇呭~鍙傛暟openid锛乼rade_type涓篔SAPI鏃讹紝openid涓哄繀濉弬鏁帮紒"); + } + if($inputObj->GetTrade_type() == "NATIVE" && !$inputObj->IsProduct_idSet()){ + throw new WxPayException("缁熶竴鏀粯鎺ュ彛涓紝缂哄皯蹇呭~鍙傛暟product_id锛乼rade_type涓篔SAPI鏃讹紝product_id涓哄繀濉弬鏁帮紒"); + } + + //寮傛閫氱煡url鏈缃紝鍒欎娇鐢ㄩ厤缃枃浠朵腑鐨剈rl + if(!$inputObj->IsNotify_urlSet() && $config->GetNotifyUrl() != ""){ + $inputObj->SetNotify_url($config->GetNotifyUrl());//寮傛閫氱煡url + } + + $inputObj->SetAppid($config->GetAppId());//鍏紬璐﹀彿ID + $inputObj->SetMch_id($config->GetMerchantId());//鍟嗘埛鍙 + $inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//缁堢ip + $inputObj->SetNonce_str(self::getNonceStr());//闅忔満瀛楃涓 + + //绛惧悕 + $inputObj->SetSign($config); + $xml = $inputObj->ToXml(); + + $startTimeStamp = self::getMillisecond();//璇锋眰寮濮嬫椂闂 + $response = self::postXmlCurl($config, $xml, $url, false, $timeOut); + $result = WxPayResults::Init($config, $response); + self::reportCostTime($config, $url, $startTimeStamp, $result);//涓婃姤璇锋眰鑺辫垂鏃堕棿 + + return $result; + } + + /** + * + * 鏌ヨ璁㈠崟锛學xPayOrderQuery涓璷ut_trade_no銆乼ransaction_id鑷冲皯濉竴涓 + * appid銆乵chid銆乻pbill_create_ip銆乶once_str涓嶉渶瑕佸~鍏 + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param WxPayOrderQuery $inputObj + * @param int $timeOut + * @throws WxPayException + * @return 鎴愬姛鏃惰繑鍥烇紝鍏朵粬鎶涘紓甯 + */ + public static function orderQuery($config, $inputObj, $timeOut = 6) + { + $url = "https://api.mch.weixin.qq.com/pay/orderquery"; + //妫娴嬪繀濉弬鏁 + if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) { + throw new WxPayException("璁㈠崟鏌ヨ鎺ュ彛涓紝out_trade_no銆乼ransaction_id鑷冲皯濉竴涓紒"); + } + $inputObj->SetAppid($config->GetAppId());//鍏紬璐﹀彿ID + $inputObj->SetMch_id($config->GetMerchantId());//鍟嗘埛鍙 + $inputObj->SetNonce_str(self::getNonceStr());//闅忔満瀛楃涓 + + $inputObj->SetSign($config);//绛惧悕 + $xml = $inputObj->ToXml(); + + $startTimeStamp = self::getMillisecond();//璇锋眰寮濮嬫椂闂 + $response = self::postXmlCurl($config, $xml, $url, false, $timeOut); + $result = WxPayResults::Init($config, $response); + self::reportCostTime($config, $url, $startTimeStamp, $result);//涓婃姤璇锋眰鑺辫垂鏃堕棿 + + return $result; + } + + /** + * + * 鍏抽棴璁㈠崟锛學xPayCloseOrder涓璷ut_trade_no蹇呭~ + * appid銆乵chid銆乻pbill_create_ip銆乶once_str涓嶉渶瑕佸~鍏 + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param WxPayCloseOrder $inputObj + * @param int $timeOut + * @throws WxPayException + * @return 鎴愬姛鏃惰繑鍥烇紝鍏朵粬鎶涘紓甯 + */ + public static function closeOrder($config, $inputObj, $timeOut = 6) + { + $url = "https://api.mch.weixin.qq.com/pay/closeorder"; + //妫娴嬪繀濉弬鏁 + if(!$inputObj->IsOut_trade_noSet()) { + throw new WxPayException("璁㈠崟鏌ヨ鎺ュ彛涓紝out_trade_no蹇呭~锛"); + } + $inputObj->SetAppid($config->GetAppId());//鍏紬璐﹀彿ID + $inputObj->SetMch_id($config->GetMerchantId());//鍟嗘埛鍙 + $inputObj->SetNonce_str(self::getNonceStr());//闅忔満瀛楃涓 + + $inputObj->SetSign($config);//绛惧悕 + $xml = $inputObj->ToXml(); + + $startTimeStamp = self::getMillisecond();//璇锋眰寮濮嬫椂闂 + $response = self::postXmlCurl($config, $xml, $url, false, $timeOut); + $result = WxPayResults::Init($config, $response); + self::reportCostTime($config, $url, $startTimeStamp, $result);//涓婃姤璇锋眰鑺辫垂鏃堕棿 + + return $result; + } + + /** + * + * 鐢宠閫娆撅紝WxPayRefund涓璷ut_trade_no銆乼ransaction_id鑷冲皯濉竴涓笖 + * out_refund_no銆乼otal_fee銆乺efund_fee銆乷p_user_id涓哄繀濉弬鏁 + * appid銆乵chid銆乻pbill_create_ip銆乶once_str涓嶉渶瑕佸~鍏 + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param WxPayRefund $inputObj + * @param int $timeOut + * @throws WxPayException + * @return 鎴愬姛鏃惰繑鍥烇紝鍏朵粬鎶涘紓甯 + */ + public static function refund($config, $inputObj, $timeOut = 6) + { + $url = "https://api.mch.weixin.qq.com/secapi/pay/refund"; + //妫娴嬪繀濉弬鏁 + if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) { + throw new WxPayException("閫娆剧敵璇锋帴鍙d腑锛宱ut_trade_no銆乼ransaction_id鑷冲皯濉竴涓紒"); + }else if(!$inputObj->IsOut_refund_noSet()){ + throw new WxPayException("閫娆剧敵璇锋帴鍙d腑锛岀己灏戝繀濉弬鏁皁ut_refund_no锛"); + }else if(!$inputObj->IsTotal_feeSet()){ + throw new WxPayException("閫娆剧敵璇锋帴鍙d腑锛岀己灏戝繀濉弬鏁皌otal_fee锛"); + }else if(!$inputObj->IsRefund_feeSet()){ + throw new WxPayException("閫娆剧敵璇锋帴鍙d腑锛岀己灏戝繀濉弬鏁皉efund_fee锛"); + }else if(!$inputObj->IsOp_user_idSet()){ + throw new WxPayException("閫娆剧敵璇锋帴鍙d腑锛岀己灏戝繀濉弬鏁皁p_user_id锛"); + } + $inputObj->SetAppid($config->GetAppId());//鍏紬璐﹀彿ID + $inputObj->SetMch_id($config->GetMerchantId());//鍟嗘埛鍙 + $inputObj->SetNonce_str(self::getNonceStr());//闅忔満瀛楃涓 + + $inputObj->SetSign($config);//绛惧悕 + $xml = $inputObj->ToXml(); + $startTimeStamp = self::getMillisecond();//璇锋眰寮濮嬫椂闂 + $response = self::postXmlCurl($config, $xml, $url, true, $timeOut); + $result = WxPayResults::Init($config, $response); + self::reportCostTime($config, $url, $startTimeStamp, $result);//涓婃姤璇锋眰鑺辫垂鏃堕棿 + + return $result; + } + + /** + * + * 鏌ヨ閫娆 + * 鎻愪氦閫娆剧敵璇峰悗锛岄氳繃璋冪敤璇ユ帴鍙f煡璇㈤娆剧姸鎬併傞娆炬湁涓瀹氬欢鏃讹紝 + * 鐢ㄩ浂閽辨敮浠樼殑閫娆20鍒嗛挓鍐呭埌璐︼紝閾惰鍗℃敮浠樼殑閫娆3涓伐浣滄棩鍚庨噸鏂版煡璇㈤娆剧姸鎬併 + * WxPayRefundQuery涓璷ut_refund_no銆乷ut_trade_no銆乼ransaction_id銆乺efund_id鍥涗釜鍙傛暟蹇呭~涓涓 + * appid銆乵chid銆乻pbill_create_ip銆乶once_str涓嶉渶瑕佸~鍏 + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param WxPayRefundQuery $inputObj + * @param int $timeOut + * @throws WxPayException + * @return 鎴愬姛鏃惰繑鍥烇紝鍏朵粬鎶涘紓甯 + */ + public static function refundQuery($config, $inputObj, $timeOut = 6) + { + $url = "https://api.mch.weixin.qq.com/pay/refundquery"; + //妫娴嬪繀濉弬鏁 + if(!$inputObj->IsOut_refund_noSet() && + !$inputObj->IsOut_trade_noSet() && + !$inputObj->IsTransaction_idSet() && + !$inputObj->IsRefund_idSet()) { + throw new WxPayException("閫娆炬煡璇㈡帴鍙d腑锛宱ut_refund_no銆乷ut_trade_no銆乼ransaction_id銆乺efund_id鍥涗釜鍙傛暟蹇呭~涓涓紒"); + } + $inputObj->SetAppid($config->GetAppId());//鍏紬璐﹀彿ID + $inputObj->SetMch_id($config->GetMerchantId());//鍟嗘埛鍙 + $inputObj->SetNonce_str(self::getNonceStr());//闅忔満瀛楃涓 + + $inputObj->SetSign($config);//绛惧悕 + $xml = $inputObj->ToXml(); + + $startTimeStamp = self::getMillisecond();//璇锋眰寮濮嬫椂闂 + $response = self::postXmlCurl($config, $xml, $url, false, $timeOut); + $result = WxPayResults::Init($config, $response); + self::reportCostTime($config, $url, $startTimeStamp, $result);//涓婃姤璇锋眰鑺辫垂鏃堕棿 + + return $result; + } + + /** + * 涓嬭浇瀵硅处鍗曪紝WxPayDownloadBill涓璪ill_date涓哄繀濉弬鏁 + * appid銆乵chid銆乻pbill_create_ip銆乶once_str涓嶉渶瑕佸~鍏 + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param WxPayDownloadBill $inputObj + * @param int $timeOut + * @throws WxPayException + * @return 鎴愬姛鏃惰繑鍥烇紝鍏朵粬鎶涘紓甯 + */ + public static function downloadBill($config, $inputObj, $timeOut = 6) + { + $url = "https://api.mch.weixin.qq.com/pay/downloadbill"; + //妫娴嬪繀濉弬鏁 + if(!$inputObj->IsBill_dateSet()) { + throw new WxPayException("瀵硅处鍗曟帴鍙d腑锛岀己灏戝繀濉弬鏁癰ill_date锛"); + } + $inputObj->SetAppid($config->GetAppId());//鍏紬璐﹀彿ID + $inputObj->SetMch_id($config->GetMerchantId());//鍟嗘埛鍙 + $inputObj->SetNonce_str(self::getNonceStr());//闅忔満瀛楃涓 + + $inputObj->SetSign($config);//绛惧悕 + $xml = $inputObj->ToXml(); + + $response = self::postXmlCurl($config, $xml, $url, false, $timeOut); + if(substr($response, 0 , 5) == ""){ + return ""; + } + return $response; + } + + /** + * 鎻愪氦琚壂鏀粯API + * 鏀堕摱鍛樹娇鐢ㄦ壂鐮佽澶囪鍙栧井淇$敤鎴峰埛鍗℃巿鏉冪爜浠ュ悗锛屼簩缁寸爜鎴栨潯鐮佷俊鎭紶閫佽嚦鍟嗘埛鏀堕摱鍙帮紝 + * 鐢卞晢鎴锋敹閾跺彴鎴栬呭晢鎴峰悗鍙拌皟鐢ㄨ鎺ュ彛鍙戣捣鏀粯銆 + * WxPayWxPayMicroPay涓璪ody銆乷ut_trade_no銆乼otal_fee銆乤uth_code鍙傛暟蹇呭~ + * appid銆乵chid銆乻pbill_create_ip銆乶once_str涓嶉渶瑕佸~鍏 + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param WxPayWxPayMicroPay $inputObj + * @param int $timeOut + */ + public static function micropay($config, $inputObj, $timeOut = 10) + { + $url = "https://api.mch.weixin.qq.com/pay/micropay"; + //妫娴嬪繀濉弬鏁 + if(!$inputObj->IsBodySet()) { + throw new WxPayException("鎻愪氦琚壂鏀粯API鎺ュ彛涓紝缂哄皯蹇呭~鍙傛暟body锛"); + } else if(!$inputObj->IsOut_trade_noSet()) { + throw new WxPayException("鎻愪氦琚壂鏀粯API鎺ュ彛涓紝缂哄皯蹇呭~鍙傛暟out_trade_no锛"); + } else if(!$inputObj->IsTotal_feeSet()) { + throw new WxPayException("鎻愪氦琚壂鏀粯API鎺ュ彛涓紝缂哄皯蹇呭~鍙傛暟total_fee锛"); + } else if(!$inputObj->IsAuth_codeSet()) { + throw new WxPayException("鎻愪氦琚壂鏀粯API鎺ュ彛涓紝缂哄皯蹇呭~鍙傛暟auth_code锛"); + } + + $inputObj->SetSpbill_create_ip($_SERVER['REMOTE_ADDR']);//缁堢ip + $inputObj->SetAppid($config->GetAppId());//鍏紬璐﹀彿ID + $inputObj->SetMch_id($config->GetMerchantId());//鍟嗘埛鍙 + $inputObj->SetNonce_str(self::getNonceStr());//闅忔満瀛楃涓 + + $inputObj->SetSign($config);//绛惧悕 + $xml = $inputObj->ToXml(); + + $startTimeStamp = self::getMillisecond();//璇锋眰寮濮嬫椂闂 + $response = self::postXmlCurl($config, $xml, $url, false, $timeOut); + $result = WxPayResults::Init($config, $response); + self::reportCostTime($config, $url, $startTimeStamp, $result);//涓婃姤璇锋眰鑺辫垂鏃堕棿 + + return $result; + } + + /** + * + * 鎾ら攢璁㈠崟API鎺ュ彛锛學xPayReverse涓弬鏁皁ut_trade_no鍜宼ransaction_id蹇呴』濉啓涓涓 + * appid銆乵chid銆乻pbill_create_ip銆乶once_str涓嶉渶瑕佸~鍏 + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param WxPayReverse $inputObj + * @param int $timeOut + * @throws WxPayException + */ + public static function reverse($config, $inputObj, $timeOut = 6) + { + $url = "https://api.mch.weixin.qq.com/secapi/pay/reverse"; + //妫娴嬪繀濉弬鏁 + if(!$inputObj->IsOut_trade_noSet() && !$inputObj->IsTransaction_idSet()) { + throw new WxPayException("鎾ら攢璁㈠崟API鎺ュ彛涓紝鍙傛暟out_trade_no鍜宼ransaction_id蹇呴』濉啓涓涓紒"); + } + + $inputObj->SetAppid($config->GetAppId());//鍏紬璐﹀彿ID + $inputObj->SetMch_id($config->GetMerchantId());//鍟嗘埛鍙 + $inputObj->SetNonce_str(self::getNonceStr());//闅忔満瀛楃涓 + + $inputObj->SetSign($config);//绛惧悕 + $xml = $inputObj->ToXml(); + + $startTimeStamp = self::getMillisecond();//璇锋眰寮濮嬫椂闂 + $response = self::postXmlCurl($config, $xml, $url, true, $timeOut); + $result = WxPayResults::Init($config, $response); + self::reportCostTime($config, $url, $startTimeStamp, $result);//涓婃姤璇锋眰鑺辫垂鏃堕棿 + + return $result; + } + + /** + * + * 娴嬮熶笂鎶ワ紝璇ユ柟娉曞唴閮ㄥ皝瑁呭湪report涓紝浣跨敤鏃惰娉ㄦ剰寮傚父娴佺▼ + * WxPayReport涓璱nterface_url銆乺eturn_code銆乺esult_code銆乽ser_ip銆乪xecute_time_蹇呭~ + * appid銆乵chid銆乻pbill_create_ip銆乶once_str涓嶉渶瑕佸~鍏 + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param WxPayReport $inputObj + * @param int $timeOut + * @throws WxPayException + * @return 鎴愬姛鏃惰繑鍥烇紝鍏朵粬鎶涘紓甯 + */ + public static function report($config, $inputObj, $timeOut = 1) + { + $url = "https://api.mch.weixin.qq.com/payitil/report"; + //妫娴嬪繀濉弬鏁 + if(!$inputObj->IsInterface_urlSet()) { + throw new WxPayException("鎺ュ彛URL锛岀己灏戝繀濉弬鏁癷nterface_url锛"); + } if(!$inputObj->IsReturn_codeSet()) { + throw new WxPayException("杩斿洖鐘舵佺爜锛岀己灏戝繀濉弬鏁皉eturn_code锛"); + } if(!$inputObj->IsResult_codeSet()) { + throw new WxPayException("涓氬姟缁撴灉锛岀己灏戝繀濉弬鏁皉esult_code锛"); + } if(!$inputObj->IsUser_ipSet()) { + throw new WxPayException("璁块棶鎺ュ彛IP锛岀己灏戝繀濉弬鏁皍ser_ip锛"); + } if(!$inputObj->IsExecute_time_Set()) { + throw new WxPayException("鎺ュ彛鑰楁椂锛岀己灏戝繀濉弬鏁癳xecute_time_锛"); + } + $inputObj->SetAppid($config->GetAppId());//鍏紬璐﹀彿ID + $inputObj->SetMch_id($config->GetMerchantId());//鍟嗘埛鍙 + $inputObj->SetUser_ip($_SERVER['REMOTE_ADDR']);//缁堢ip + $inputObj->SetTime(date("YmdHis"));//鍟嗘埛涓婃姤鏃堕棿 + $inputObj->SetNonce_str(self::getNonceStr());//闅忔満瀛楃涓 + + $inputObj->SetSign($config);//绛惧悕 + $xml = $inputObj->ToXml(); + + $startTimeStamp = self::getMillisecond();//璇锋眰寮濮嬫椂闂 + $response = self::postXmlCurl($config, $xml, $url, false, $timeOut); + return $response; + } + + /** + * + * 鐢熸垚浜岀淮鐮佽鍒,妯″紡涓鐢熸垚鏀粯浜岀淮鐮 + * appid銆乵chid銆乻pbill_create_ip銆乶once_str涓嶉渶瑕佸~鍏 + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param WxPayBizPayUrl $inputObj + * @param int $timeOut + * @throws WxPayException + * @return 鎴愬姛鏃惰繑鍥烇紝鍏朵粬鎶涘紓甯 + */ + public static function bizpayurl($config, $inputObj, $timeOut = 6) + { + if(!$inputObj->IsProduct_idSet()){ + throw new WxPayException("鐢熸垚浜岀淮鐮侊紝缂哄皯蹇呭~鍙傛暟product_id锛"); + } + + $inputObj->SetAppid($config->GetAppId());//鍏紬璐﹀彿ID + $inputObj->SetMch_id($config->GetMerchantId());//鍟嗘埛鍙 + $inputObj->SetTime_stamp(time());//鏃堕棿鎴 + $inputObj->SetNonce_str(self::getNonceStr());//闅忔満瀛楃涓 + + $inputObj->SetSign($config);//绛惧悕 + + return $inputObj->GetValues(); + } + + /** + * + * 杞崲鐭摼鎺 + * 璇ユ帴鍙d富瑕佺敤浜庢壂鐮佸師鐢熸敮浠樻ā寮忎竴涓殑浜岀淮鐮侀摼鎺ヨ浆鎴愮煭閾炬帴(weixin://wxpay/s/XXXXXX)锛 + * 鍑忓皬浜岀淮鐮佹暟鎹噺锛屾彁鍗囨壂鎻忛熷害鍜岀簿纭害銆 + * appid銆乵chid銆乻pbill_create_ip銆乶once_str涓嶉渶瑕佸~鍏 + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param WxPayShortUrl $inputObj + * @param int $timeOut + * @throws WxPayException + * @return 鎴愬姛鏃惰繑鍥烇紝鍏朵粬鎶涘紓甯 + */ + public static function shorturl($config, $inputObj, $timeOut = 6) + { + $url = "https://api.mch.weixin.qq.com/tools/shorturl"; + //妫娴嬪繀濉弬鏁 + if(!$inputObj->IsLong_urlSet()) { + throw new WxPayException("闇瑕佽浆鎹㈢殑URL锛岀鍚嶇敤鍘熶覆锛屼紶杈撻渶URL encode锛"); + } + $inputObj->SetAppid($config->GetAppId());//鍏紬璐﹀彿ID + $inputObj->SetMch_id($config->GetMerchantId());//鍟嗘埛鍙 + $inputObj->SetNonce_str(self::getNonceStr());//闅忔満瀛楃涓 + + $inputObj->SetSign($config);//绛惧悕 + $xml = $inputObj->ToXml(); + + $startTimeStamp = self::getMillisecond();//璇锋眰寮濮嬫椂闂 + $response = self::postXmlCurl($config, $xml, $url, false, $timeOut); + $result = WxPayResults::Init($config, $response); + self::reportCostTime($config, $url, $startTimeStamp, $result);//涓婃姤璇锋眰鑺辫垂鏃堕棿 + + return $result; + } + + /** + * + * 鏀粯缁撴灉閫氱敤閫氱煡 + * @param function $callback + * 鐩存帴鍥炶皟鍑芥暟浣跨敤鏂规硶: notify(you_function); + * 鍥炶皟绫绘垚鍛樺嚱鏁版柟娉:notify(array($this, you_function)); + * $callback 鍘熷瀷涓猴細function function_name($data){} + */ + public static function notify($config, $callback, &$msg) + { + //鑾峰彇閫氱煡鐨勬暟鎹 + $xml = isset($GLOBALS['HTTP_RAW_POST_DATA']) ? $GLOBALS['HTTP_RAW_POST_DATA'] : file_get_contents("php://input"); + if (empty($xml)) { + # 濡傛灉娌℃湁鏁版嵁锛岀洿鎺ヨ繑鍥炲け璐 + return false; + } + + //濡傛灉杩斿洖鎴愬姛鍒欓獙璇佺鍚 + try { + $result = WxPayNotifyResults::Init($config, $xml); + } catch (WxPayException $e){ + $msg = $e->errorMessage(); + return false; + } + + return call_user_func($callback, $result); + } + + /** + * + * 浜х敓闅忔満瀛楃涓诧紝涓嶉暱浜32浣 + * @param int $length + * @return 浜х敓鐨勯殢鏈哄瓧绗︿覆 + */ + public static function getNonceStr($length = 32) + { + $chars = "abcdefghijklmnopqrstuvwxyz0123456789"; + $str =""; + for ( $i = 0; $i < $length; $i++ ) { + $str .= substr($chars, mt_rand(0, strlen($chars)-1), 1); + } + return $str; + } + + /** + * 鐩存帴杈撳嚭xml + * @param string $xml + */ + public static function replyNotify($xml) + { + echo $xml; + } + + /** + * + * 涓婃姤鏁版嵁锛 涓婃姤鐨勬椂鍊欏皢灞忚斀鎵鏈夊紓甯告祦绋 + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param string $usrl + * @param int $startTimeStamp + * @param array $data + */ + private static function reportCostTime($config, $url, $startTimeStamp, $data) + { + //濡傛灉涓嶉渶瑕佷笂鎶ユ暟鎹 + $reportLevenl = $config->GetReportLevenl(); + if($reportLevenl == 0){ + return; + } + //濡傛灉浠呭け璐ヤ笂鎶 + if($reportLevenl == 1 && + array_key_exists("return_code", $data) && + $data["return_code"] == "SUCCESS" && + array_key_exists("result_code", $data) && + $data["result_code"] == "SUCCESS") + { + return; + } + + //涓婃姤閫昏緫 + $endTimeStamp = self::getMillisecond(); + $objInput = new WxPayReport(); + $objInput->SetInterface_url($url); + $objInput->SetExecute_time_($endTimeStamp - $startTimeStamp); + //杩斿洖鐘舵佺爜 + if(array_key_exists("return_code", $data)){ + $objInput->SetReturn_code($data["return_code"]); + } + //杩斿洖淇℃伅 + if(array_key_exists("return_msg", $data)){ + $objInput->SetReturn_msg($data["return_msg"]); + } + //涓氬姟缁撴灉 + if(array_key_exists("result_code", $data)){ + $objInput->SetResult_code($data["result_code"]); + } + //閿欒浠g爜 + if(array_key_exists("err_code", $data)){ + $objInput->SetErr_code($data["err_code"]); + } + //閿欒浠g爜鎻忚堪 + if(array_key_exists("err_code_des", $data)){ + $objInput->SetErr_code_des($data["err_code_des"]); + } + //鍟嗘埛璁㈠崟鍙 + if(array_key_exists("out_trade_no", $data)){ + $objInput->SetOut_trade_no($data["out_trade_no"]); + } + //璁惧鍙 + if(array_key_exists("device_info", $data)){ + $objInput->SetDevice_info($data["device_info"]); + } + + try{ + self::report($config, $objInput); + } catch (WxPayException $e){ + //涓嶅仛浠讳綍澶勭悊 + } + } + + /** + * 浠ost鏂瑰紡鎻愪氦xml鍒板搴旂殑鎺ュ彛url + * + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param string $xml 闇瑕乸ost鐨剎ml鏁版嵁 + * @param string $url url + * @param bool $useCert 鏄惁闇瑕佽瘉涔︼紝榛樿涓嶉渶瑕 + * @param int $second url鎵ц瓒呮椂鏃堕棿锛岄粯璁30s + * @throws WxPayException + */ + private static function postXmlCurl($config, $xml, $url, $useCert = false, $second = 30) + { + $ch = curl_init(); + $curlVersion = curl_version(); + $ua = "WXPaySDK/".self::$VERSION." (".PHP_OS.") PHP/".PHP_VERSION." CURL/".$curlVersion['version']." " + .$config->GetMerchantId(); + + //璁剧疆瓒呮椂 + curl_setopt($ch, CURLOPT_TIMEOUT, $second); + + $proxyHost = "0.0.0.0"; + $proxyPort = 0; + $config->GetProxy($proxyHost, $proxyPort); + //濡傛灉鏈夐厤缃唬鐞嗚繖閲屽氨璁剧疆浠g悊 + if($proxyHost != "0.0.0.0" && $proxyPort != 0){ + curl_setopt($ch,CURLOPT_PROXY, $proxyHost); + curl_setopt($ch,CURLOPT_PROXYPORT, $proxyPort); + } + curl_setopt($ch,CURLOPT_URL, $url); + curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,TRUE); + curl_setopt($ch,CURLOPT_SSL_VERIFYHOST,2);//涓ユ牸鏍¢獙 + curl_setopt($ch,CURLOPT_USERAGENT, $ua); + //璁剧疆header + curl_setopt($ch, CURLOPT_HEADER, FALSE); + //瑕佹眰缁撴灉涓哄瓧绗︿覆涓旇緭鍑哄埌灞忓箷涓 + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + + if($useCert == true){ + //璁剧疆璇佷功 + //浣跨敤璇佷功锛歝ert 涓 key 鍒嗗埆灞炰簬涓や釜.pem鏂囦欢 + //璇佷功鏂囦欢璇锋斁鍏ユ湇鍔″櫒鐨勯潪web鐩綍涓 + $sslCertPath = ""; + $sslKeyPath = ""; + $config->GetSSLCertPath($sslCertPath, $sslKeyPath); + curl_setopt($ch,CURLOPT_SSLCERTTYPE,'PEM'); + curl_setopt($ch,CURLOPT_SSLCERT, $sslCertPath); + curl_setopt($ch,CURLOPT_SSLKEYTYPE,'PEM'); + curl_setopt($ch,CURLOPT_SSLKEY, $sslKeyPath); + } + //post鎻愪氦鏂瑰紡 + curl_setopt($ch, CURLOPT_POST, TRUE); + curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); + //杩愯curl + $data = curl_exec($ch); + //杩斿洖缁撴灉 + if($data){ + curl_close($ch); + return $data; + } else { + $error = curl_errno($ch); + curl_close($ch); + throw new WxPayException("curl鍑洪敊锛岄敊璇爜:$error"); + } + } + + /** + * 鑾峰彇姣绾у埆鐨勬椂闂存埑 + */ + private static function getMillisecond() + { + //鑾峰彇姣鐨勬椂闂存埑 + $time = explode ( " ", microtime () ); + $time = $time[1] . ($time[0] * 1000); + $time2 = explode( ".", $time ); + $time = $time2[0]; + return $time; + } +} + diff --git a/public/php_sdk_v3.0.10/lib/WxPay.Config.Interface.php b/public/php_sdk_v3.0.10/lib/WxPay.Config.Interface.php new file mode 100755 index 0000000000000000000000000000000000000000..3129a04c51f57e7eb84adfa3c9ce6cd2b64abb50 --- /dev/null +++ b/public/php_sdk_v3.0.10/lib/WxPay.Config.Interface.php @@ -0,0 +1,76 @@ +values['sign_type'] = $sign_type; + return $sign_type; + } + + /** + * 璁剧疆绛惧悕锛岃瑙佺鍚嶇敓鎴愮畻娉 + * @param string $value + **/ + public function SetSign($config) + { + $sign = $this->MakeSign($config); + $this->values['sign'] = $sign; + return $sign; + } + + /** + * 鑾峰彇绛惧悕锛岃瑙佺鍚嶇敓鎴愮畻娉曠殑鍊 + * @return 鍊 + **/ + public function GetSign() + { + return $this->values['sign']; + } + + /** + * 鍒ゆ柇绛惧悕锛岃瑙佺鍚嶇敓鎴愮畻娉曟槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsSignSet() + { + return array_key_exists('sign', $this->values); + } + + /** + * 杈撳嚭xml瀛楃 + * @throws WxPayException + **/ + public function ToXml() + { + if(!is_array($this->values) || count($this->values) <= 0) + { + throw new WxPayException("鏁扮粍鏁版嵁寮傚父锛"); + } + + $xml = ""; + foreach ($this->values as $key=>$val) + { + if (is_numeric($val)){ + $xml.="<".$key.">".$val.""; + }else{ + $xml.="<".$key.">"; + } + } + $xml.=""; + return $xml; + } + + /** + * 灏唜ml杞负array + * @param string $xml + * @throws WxPayException + */ + public function FromXml($xml) + { + if(!$xml){ + throw new WxPayException("xml鏁版嵁寮傚父锛"); + } + //灏哫ML杞负array + //绂佹寮曠敤澶栭儴xml瀹炰綋 + libxml_disable_entity_loader(true); + $this->values = json_decode(json_encode(simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA)), true); + return $this->values; + } + + /** + * 鏍煎紡鍖栧弬鏁版牸寮忓寲鎴恥rl鍙傛暟 + */ + public function ToUrlParams() + { + $buff = ""; + foreach ($this->values as $k => $v) + { + if($k != "sign" && $v != "" && !is_array($v)){ + $buff .= $k . "=" . $v . "&"; + } + } + + $buff = trim($buff, "&"); + return $buff; + } + + /** + * 鐢熸垚绛惧悕 + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param bool $needSignType 鏄惁闇瑕佽ˉsigntype + * @return 绛惧悕锛屾湰鍑芥暟涓嶈鐩杝ign鎴愬憳鍙橀噺锛屽瑕佽缃鍚嶉渶瑕佽皟鐢⊿etSign鏂规硶璧嬪 + */ + public function MakeSign($config, $needSignType = true) + { + if($needSignType) { + $this->SetSignType($config->GetSignType()); + } + //绛惧悕姝ラ涓锛氭寜瀛楀吀搴忔帓搴忓弬鏁 + ksort($this->values); + $string = $this->ToUrlParams(); + //绛惧悕姝ラ浜岋細鍦╯tring鍚庡姞鍏EY + $string = $string . "&key=".$config->GetKey(); + //绛惧悕姝ラ涓夛細MD5鍔犲瘑鎴栬匟MAC-SHA256 + if($config->GetSignType() == "MD5"){ + $string = md5($string); + } else if($config->GetSignType() == "HMAC-SHA256") { + $string = hash_hmac("sha256",$string ,$config->GetKey()); + } else { + throw new WxPayException("绛惧悕绫诲瀷涓嶆敮鎸侊紒"); + } + + //绛惧悕姝ラ鍥涳細鎵鏈夊瓧绗﹁浆涓哄ぇ鍐 + $result = strtoupper($string); + return $result; + } + + /** + * 鑾峰彇璁剧疆鐨勫 + */ + public function GetValues() + { + return $this->values; + } +} + +/** + * + * 鍙娇鐢╩d5绠楁硶杩涜绛惧悕锛 涓嶇閰嶇疆鐨勬槸浠涔堢鍚嶆柟寮忥紝閮藉彧鏀寔md5绛惧悕鏂瑰紡 + * +**/ +class WxPayDataBaseSignMd5 extends WxPayDataBase +{ + /** + * 鐢熸垚绛惧悕 - 閲嶅啓璇ユ柟娉 + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param bool $needSignType 鏄惁闇瑕佽ˉsigntype + * @return 绛惧悕锛屾湰鍑芥暟涓嶈鐩杝ign鎴愬憳鍙橀噺锛屽瑕佽缃鍚嶉渶瑕佽皟鐢⊿etSign鏂规硶璧嬪 + */ + public function MakeSign($config, $needSignType = false) + { + if($needSignType) { + $this->SetSignType($config->GetSignType()); + } + //绛惧悕姝ラ涓锛氭寜瀛楀吀搴忔帓搴忓弬鏁 + ksort($this->values); + $string = $this->ToUrlParams(); + //绛惧悕姝ラ浜岋細鍦╯tring鍚庡姞鍏EY + $string = $string . "&key=".$config->GetKey(); + //绛惧悕姝ラ涓夛細MD5鍔犲瘑 + $string = md5($string); + //绛惧悕姝ラ鍥涳細鎵鏈夊瓧绗﹁浆涓哄ぇ鍐 + $result = strtoupper($string); + return $result; + } +} + +/** + * + * 鎺ュ彛璋冪敤缁撴灉绫 + * @author widyhu + * + */ +class WxPayResults extends WxPayDataBase +{ + /** + * 鐢熸垚绛惧悕 - 閲嶅啓璇ユ柟娉 + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param bool $needSignType 鏄惁闇瑕佽ˉsigntype + * @return 绛惧悕锛屾湰鍑芥暟涓嶈鐩杝ign鎴愬憳鍙橀噺锛屽瑕佽缃鍚嶉渶瑕佽皟鐢⊿etSign鏂规硶璧嬪 + */ + public function MakeSign($config, $needSignType = false) + { + //绛惧悕姝ラ涓锛氭寜瀛楀吀搴忔帓搴忓弬鏁 + ksort($this->values); + $string = $this->ToUrlParams(); + //绛惧悕姝ラ浜岋細鍦╯tring鍚庡姞鍏EY + $string = $string . "&key=".$config->GetKey(); + //绛惧悕姝ラ涓夛細MD5鍔犲瘑鎴栬匟MAC-SHA256 + if(strlen($this->GetSign()) <= 32){ + //濡傛灉绛惧悕灏忎簬绛変簬32涓,鍒欎娇鐢╩d5楠岃瘉 + $string = md5($string); + } else { + //鏄敤sha256鏍¢獙 + $string = hash_hmac("sha256",$string ,$config->GetKey()); + } + //绛惧悕姝ラ鍥涳細鎵鏈夊瓧绗﹁浆涓哄ぇ鍐 + $result = strtoupper($string); + return $result; + } + + /** + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * 妫娴嬬鍚 + */ + public function CheckSign($config) + { + if(!$this->IsSignSet()){ + throw new WxPayException("绛惧悕閿欒锛"); + } + + $sign = $this->MakeSign($config, false); + if($this->GetSign() == $sign){ + //绛惧悕姝g‘ + return true; + } + throw new WxPayException("绛惧悕閿欒锛"); + } + + /** + * + * 浣跨敤鏁扮粍鍒濆鍖 + * @param array $array + */ + public function FromArray($array) + { + $this->values = $array; + } + + /** + * + * 浣跨敤鏁扮粍鍒濆鍖栧璞 + * @param array $array + * @param 鏄惁妫娴嬬鍚 $noCheckSign + */ + public static function InitFromArray($config, $array, $noCheckSign = false) + { + $obj = new self(); + $obj->FromArray($array); + if($noCheckSign == false){ + $obj->CheckSign($config); + } + return $obj; + } + + /** + * + * 璁剧疆鍙傛暟 + * @param string $key + * @param string $value + */ + public function SetData($key, $value) + { + $this->values[$key] = $value; + } + + /** + * 灏唜ml杞负array + * @param WxPayConfigInterface $config 閰嶇疆瀵硅薄 + * @param string $xml + * @throws WxPayException + */ + public static function Init($config, $xml) + { + $obj = new self(); + $obj->FromXml($xml); + //澶辫触鍒欑洿鎺ヨ繑鍥炲け璐 + if($obj->values['return_code'] != 'SUCCESS') { + foreach ($obj->values as $key => $value) { + #闄や簡return_code鍜宺eturn_msg涔嬪鍏朵粬鐨勫弬鏁板瓨鍦紝鍒欐姤閿 + if($key != "return_code" && $key != "return_msg"){ + throw new WxPayException("杈撳叆鏁版嵁瀛樺湪寮傚父锛"); + return false; + } + } + return $obj->GetValues(); + } + $obj->CheckSign($config); + return $obj->GetValues(); + } +} + +/** + * + * 鍥炶皟鍥炲寘鏁版嵁鍩虹被 + * + **/ +class WxPayNotifyResults extends WxPayResults +{ + /** + * 灏唜ml杞负array + * @param WxPayConfigInterface $config + * @param string $xml + * @return WxPayNotifyResults + * @throws WxPayException + */ + public static function Init($config, $xml) + { + $obj = new self(); + $obj->FromXml($xml); + //澶辫触鍒欑洿鎺ヨ繑鍥炲け璐 + $obj->CheckSign($config); + return $obj; + } +} + +/** + * + * 鍥炶皟鍩虹绫 + * @author widyhu + * + */ +class WxPayNotifyReply extends WxPayDataBaseSignMd5 +{ + /** + * + * 璁剧疆閿欒鐮 FAIL 鎴栬 SUCCESS + * @param string + */ + public function SetReturn_code($return_code) + { + $this->values['return_code'] = $return_code; + } + + /** + * + * 鑾峰彇閿欒鐮 FAIL 鎴栬 SUCCESS + * @return string $return_code + */ + public function GetReturn_code() + { + return $this->values['return_code']; + } + + /** + * + * 璁剧疆閿欒淇℃伅 + * @param string $return_code + */ + public function SetReturn_msg($return_msg) + { + $this->values['return_msg'] = $return_msg; + } + + /** + * + * 鑾峰彇閿欒淇℃伅 + * @return string + */ + public function GetReturn_msg() + { + return $this->values['return_msg']; + } + + /** + * + * 璁剧疆杩斿洖鍙傛暟 + * @param string $key + * @param string $value + */ + public function SetData($key, $value) + { + $this->values[$key] = $value; + } +} + +/** + * + * 缁熶竴涓嬪崟杈撳叆瀵硅薄 + * @author widyhu + * + */ +class WxPayUnifiedOrder extends WxPayDataBase +{ + /** + * 璁剧疆寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D + * @param string $value + **/ + public function SetAppid($value) + { + $this->values['appid'] = $value; + } + /** + * 鑾峰彇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鐨勫 + * @return 鍊 + **/ + public function GetAppid() + { + return $this->values['appid']; + } + /** + * 鍒ゆ柇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsAppidSet() + { + return array_key_exists('appid', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿 + * @param string $value + **/ + public function SetMch_id($value) + { + $this->values['mch_id'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鐨勫 + * @return 鍊 + **/ + public function GetMch_id() + { + return $this->values['mch_id']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsMch_idSet() + { + return array_key_exists('mch_id', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勭粓绔澶囧彿锛屽晢鎴疯嚜瀹氫箟 + * @param string $value + **/ + public function SetDevice_info($value) + { + $this->values['device_info'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勭粓绔澶囧彿锛屽晢鎴疯嚜瀹氫箟鐨勫 + * @return 鍊 + **/ + public function GetDevice_info() + { + return $this->values['device_info']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勭粓绔澶囧彿锛屽晢鎴疯嚜瀹氫箟鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsDevice_infoSet() + { + return array_key_exists('device_info', $this->values); + } + + + /** + * 璁剧疆闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶 + * @param string $value + **/ + public function SetNonce_str($value) + { + $this->values['nonce_str'] = $value; + } + /** + * 鑾峰彇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鐨勫 + * @return 鍊 + **/ + public function GetNonce_str() + { + return $this->values['nonce_str']; + } + /** + * 鍒ゆ柇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsNonce_strSet() + { + return array_key_exists('nonce_str', $this->values); + } + + /** + * 璁剧疆鍟嗗搧鎴栨敮浠樺崟绠瑕佹弿杩 + * @param string $value + **/ + public function SetBody($value) + { + $this->values['body'] = $value; + } + /** + * 鑾峰彇鍟嗗搧鎴栨敮浠樺崟绠瑕佹弿杩扮殑鍊 + * @return 鍊 + **/ + public function GetBody() + { + return $this->values['body']; + } + /** + * 鍒ゆ柇鍟嗗搧鎴栨敮浠樺崟绠瑕佹弿杩版槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsBodySet() + { + return array_key_exists('body', $this->values); + } + + + /** + * 璁剧疆鍟嗗搧鍚嶇О鏄庣粏鍒楄〃 + * @param string $value + **/ + public function SetDetail($value) + { + $this->values['detail'] = $value; + } + /** + * 鑾峰彇鍟嗗搧鍚嶇О鏄庣粏鍒楄〃鐨勫 + * @return 鍊 + **/ + public function GetDetail() + { + return $this->values['detail']; + } + /** + * 鍒ゆ柇鍟嗗搧鍚嶇О鏄庣粏鍒楄〃鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsDetailSet() + { + return array_key_exists('detail', $this->values); + } + + + /** + * 璁剧疆闄勫姞鏁版嵁锛屽湪鏌ヨAPI鍜屾敮浠橀氱煡涓師鏍疯繑鍥烇紝璇ュ瓧娈典富瑕佺敤浜庡晢鎴锋惡甯﹁鍗曠殑鑷畾涔夋暟鎹 + * @param string $value + **/ + public function SetAttach($value) + { + $this->values['attach'] = $value; + } + /** + * 鑾峰彇闄勫姞鏁版嵁锛屽湪鏌ヨAPI鍜屾敮浠橀氱煡涓師鏍疯繑鍥烇紝璇ュ瓧娈典富瑕佺敤浜庡晢鎴锋惡甯﹁鍗曠殑鑷畾涔夋暟鎹殑鍊 + * @return 鍊 + **/ + public function GetAttach() + { + return $this->values['attach']; + } + /** + * 鍒ゆ柇闄勫姞鏁版嵁锛屽湪鏌ヨAPI鍜屾敮浠橀氱煡涓師鏍疯繑鍥烇紝璇ュ瓧娈典富瑕佺敤浜庡晢鎴锋惡甯﹁鍗曠殑鑷畾涔夋暟鎹槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsAttachSet() + { + return array_key_exists('attach', $this->values); + } + + + /** + * 璁剧疆鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,32涓瓧绗﹀唴銆佸彲鍖呭惈瀛楁瘝, 鍏朵粬璇存槑瑙佸晢鎴疯鍗曞彿 + * @param string $value + **/ + public function SetOut_trade_no($value) + { + $this->values['out_trade_no'] = $value; + } + /** + * 鑾峰彇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,32涓瓧绗﹀唴銆佸彲鍖呭惈瀛楁瘝, 鍏朵粬璇存槑瑙佸晢鎴疯鍗曞彿鐨勫 + * @return 鍊 + **/ + public function GetOut_trade_no() + { + return $this->values['out_trade_no']; + } + /** + * 鍒ゆ柇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,32涓瓧绗﹀唴銆佸彲鍖呭惈瀛楁瘝, 鍏朵粬璇存槑瑙佸晢鎴疯鍗曞彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsOut_trade_noSet() + { + return array_key_exists('out_trade_no', $this->values); + } + + + /** + * 璁剧疆绗﹀悎ISO 4217鏍囧噯鐨勪笁浣嶅瓧姣嶄唬鐮侊紝榛樿浜烘皯甯侊細CNY锛屽叾浠栧煎垪琛ㄨ瑙佽揣甯佺被鍨 + * @param string $value + **/ + public function SetFee_type($value) + { + $this->values['fee_type'] = $value; + } + /** + * 鑾峰彇绗﹀悎ISO 4217鏍囧噯鐨勪笁浣嶅瓧姣嶄唬鐮侊紝榛樿浜烘皯甯侊細CNY锛屽叾浠栧煎垪琛ㄨ瑙佽揣甯佺被鍨嬬殑鍊 + * @return 鍊 + **/ + public function GetFee_type() + { + return $this->values['fee_type']; + } + /** + * 鍒ゆ柇绗﹀悎ISO 4217鏍囧噯鐨勪笁浣嶅瓧姣嶄唬鐮侊紝榛樿浜烘皯甯侊細CNY锛屽叾浠栧煎垪琛ㄨ瑙佽揣甯佺被鍨嬫槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsFee_typeSet() + { + return array_key_exists('fee_type', $this->values); + } + + + /** + * 璁剧疆璁㈠崟鎬婚噾棰濓紝鍙兘涓烘暣鏁帮紝璇﹁鏀粯閲戦 + * @param string $value + **/ + public function SetTotal_fee($value) + { + $this->values['total_fee'] = $value; + } + /** + * 鑾峰彇璁㈠崟鎬婚噾棰濓紝鍙兘涓烘暣鏁帮紝璇﹁鏀粯閲戦鐨勫 + * @return 鍊 + **/ + public function GetTotal_fee() + { + return $this->values['total_fee']; + } + /** + * 鍒ゆ柇璁㈠崟鎬婚噾棰濓紝鍙兘涓烘暣鏁帮紝璇﹁鏀粯閲戦鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsTotal_feeSet() + { + return array_key_exists('total_fee', $this->values); + } + + + /** + * 璁剧疆APP鍜岀綉椤垫敮浠樻彁浜ょ敤鎴风ip锛孨ative鏀粯濉皟鐢ㄥ井淇℃敮浠楢PI鐨勬満鍣↖P銆 + * @param string $value + **/ + public function SetSpbill_create_ip($value) + { + $this->values['spbill_create_ip'] = $value; + } + /** + * 鑾峰彇APP鍜岀綉椤垫敮浠樻彁浜ょ敤鎴风ip锛孨ative鏀粯濉皟鐢ㄥ井淇℃敮浠楢PI鐨勬満鍣↖P銆傜殑鍊 + * @return 鍊 + **/ + public function GetSpbill_create_ip() + { + return $this->values['spbill_create_ip']; + } + /** + * 鍒ゆ柇APP鍜岀綉椤垫敮浠樻彁浜ょ敤鎴风ip锛孨ative鏀粯濉皟鐢ㄥ井淇℃敮浠楢PI鐨勬満鍣↖P銆傛槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsSpbill_create_ipSet() + { + return array_key_exists('spbill_create_ip', $this->values); + } + + + /** + * 璁剧疆璁㈠崟鐢熸垚鏃堕棿锛屾牸寮忎负yyyyMMddHHmmss锛屽2009骞12鏈25鏃9鐐10鍒10绉掕〃绀轰负20091225091010銆傚叾浠栬瑙佹椂闂磋鍒 + * @param string $value + **/ + public function SetTime_start($value) + { + $this->values['time_start'] = $value; + } + /** + * 鑾峰彇璁㈠崟鐢熸垚鏃堕棿锛屾牸寮忎负yyyyMMddHHmmss锛屽2009骞12鏈25鏃9鐐10鍒10绉掕〃绀轰负20091225091010銆傚叾浠栬瑙佹椂闂磋鍒欑殑鍊 + * @return 鍊 + **/ + public function GetTime_start() + { + return $this->values['time_start']; + } + /** + * 鍒ゆ柇璁㈠崟鐢熸垚鏃堕棿锛屾牸寮忎负yyyyMMddHHmmss锛屽2009骞12鏈25鏃9鐐10鍒10绉掕〃绀轰负20091225091010銆傚叾浠栬瑙佹椂闂磋鍒欐槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsTime_startSet() + { + return array_key_exists('time_start', $this->values); + } + + + /** + * 璁剧疆璁㈠崟澶辨晥鏃堕棿锛屾牸寮忎负yyyyMMddHHmmss锛屽2009骞12鏈27鏃9鐐10鍒10绉掕〃绀轰负20091227091010銆傚叾浠栬瑙佹椂闂磋鍒 + * @param string $value + **/ + public function SetTime_expire($value) + { + $this->values['time_expire'] = $value; + } + /** + * 鑾峰彇璁㈠崟澶辨晥鏃堕棿锛屾牸寮忎负yyyyMMddHHmmss锛屽2009骞12鏈27鏃9鐐10鍒10绉掕〃绀轰负20091227091010銆傚叾浠栬瑙佹椂闂磋鍒欑殑鍊 + * @return 鍊 + **/ + public function GetTime_expire() + { + return $this->values['time_expire']; + } + /** + * 鍒ゆ柇璁㈠崟澶辨晥鏃堕棿锛屾牸寮忎负yyyyMMddHHmmss锛屽2009骞12鏈27鏃9鐐10鍒10绉掕〃绀轰负20091227091010銆傚叾浠栬瑙佹椂闂磋鍒欐槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsTime_expireSet() + { + return array_key_exists('time_expire', $this->values); + } + + + /** + * 璁剧疆鍟嗗搧鏍囪锛屼唬閲戝埜鎴栫珛鍑忎紭鎯犲姛鑳界殑鍙傛暟锛岃鏄庤瑙佷唬閲戝埜鎴栫珛鍑忎紭鎯 + * @param string $value + **/ + public function SetGoods_tag($value) + { + $this->values['goods_tag'] = $value; + } + /** + * 鑾峰彇鍟嗗搧鏍囪锛屼唬閲戝埜鎴栫珛鍑忎紭鎯犲姛鑳界殑鍙傛暟锛岃鏄庤瑙佷唬閲戝埜鎴栫珛鍑忎紭鎯犵殑鍊 + * @return 鍊 + **/ + public function GetGoods_tag() + { + return $this->values['goods_tag']; + } + /** + * 鍒ゆ柇鍟嗗搧鏍囪锛屼唬閲戝埜鎴栫珛鍑忎紭鎯犲姛鑳界殑鍙傛暟锛岃鏄庤瑙佷唬閲戝埜鎴栫珛鍑忎紭鎯犳槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsGoods_tagSet() + { + return array_key_exists('goods_tag', $this->values); + } + + + /** + * 璁剧疆鎺ユ敹寰俊鏀粯寮傛閫氱煡鍥炶皟鍦板潃 + * @param string $value + **/ + public function SetNotify_url($value) + { + $this->values['notify_url'] = $value; + } + /** + * 鑾峰彇鎺ユ敹寰俊鏀粯寮傛閫氱煡鍥炶皟鍦板潃鐨勫 + * @return 鍊 + **/ + public function GetNotify_url() + { + return $this->values['notify_url']; + } + /** + * 鍒ゆ柇鎺ユ敹寰俊鏀粯寮傛閫氱煡鍥炶皟鍦板潃鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsNotify_urlSet() + { + return array_key_exists('notify_url', $this->values); + } + + + /** + * 璁剧疆鍙栧煎涓嬶細JSAPI锛孨ATIVE锛孉PP锛岃缁嗚鏄庤鍙傛暟瑙勫畾 + * @param string $value + **/ + public function SetTrade_type($value) + { + $this->values['trade_type'] = $value; + } + /** + * 鑾峰彇鍙栧煎涓嬶細JSAPI锛孨ATIVE锛孉PP锛岃缁嗚鏄庤鍙傛暟瑙勫畾鐨勫 + * @return 鍊 + **/ + public function GetTrade_type() + { + return $this->values['trade_type']; + } + /** + * 鍒ゆ柇鍙栧煎涓嬶細JSAPI锛孨ATIVE锛孉PP锛岃缁嗚鏄庤鍙傛暟瑙勫畾鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsTrade_typeSet() + { + return array_key_exists('trade_type', $this->values); + } + + + /** + * 璁剧疆trade_type=NATIVE锛屾鍙傛暟蹇呬紶銆傛id涓轰簩缁寸爜涓寘鍚殑鍟嗗搧ID锛屽晢鎴疯嚜琛屽畾涔夈 + * @param string $value + **/ + public function SetProduct_id($value) + { + $this->values['product_id'] = $value; + } + /** + * 鑾峰彇trade_type=NATIVE锛屾鍙傛暟蹇呬紶銆傛id涓轰簩缁寸爜涓寘鍚殑鍟嗗搧ID锛屽晢鎴疯嚜琛屽畾涔夈傜殑鍊 + * @return 鍊 + **/ + public function GetProduct_id() + { + return $this->values['product_id']; + } + /** + * 鍒ゆ柇trade_type=NATIVE锛屾鍙傛暟蹇呬紶銆傛id涓轰簩缁寸爜涓寘鍚殑鍟嗗搧ID锛屽晢鎴疯嚜琛屽畾涔夈傛槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsProduct_idSet() + { + return array_key_exists('product_id', $this->values); + } + + + /** + * 璁剧疆trade_type=JSAPI锛屾鍙傛暟蹇呬紶锛岀敤鎴峰湪鍟嗘埛appid涓嬬殑鍞竴鏍囪瘑銆備笅鍗曞墠闇瑕佽皟鐢ㄣ愮綉椤垫巿鏉冭幏鍙栫敤鎴蜂俊鎭戞帴鍙h幏鍙栧埌鐢ㄦ埛鐨凮penid銆 + * @param string $value + **/ + public function SetOpenid($value) + { + $this->values['openid'] = $value; + } + /** + * 鑾峰彇trade_type=JSAPI锛屾鍙傛暟蹇呬紶锛岀敤鎴峰湪鍟嗘埛appid涓嬬殑鍞竴鏍囪瘑銆備笅鍗曞墠闇瑕佽皟鐢ㄣ愮綉椤垫巿鏉冭幏鍙栫敤鎴蜂俊鎭戞帴鍙h幏鍙栧埌鐢ㄦ埛鐨凮penid銆 鐨勫 + * @return 鍊 + **/ + public function GetOpenid() + { + return $this->values['openid']; + } + /** + * 鍒ゆ柇trade_type=JSAPI锛屾鍙傛暟蹇呬紶锛岀敤鎴峰湪鍟嗘埛appid涓嬬殑鍞竴鏍囪瘑銆備笅鍗曞墠闇瑕佽皟鐢ㄣ愮綉椤垫巿鏉冭幏鍙栫敤鎴蜂俊鎭戞帴鍙h幏鍙栧埌鐢ㄦ埛鐨凮penid銆 鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsOpenidSet() + { + return array_key_exists('openid', $this->values); + } +} + +/** + * + * 璁㈠崟鏌ヨ杈撳叆瀵硅薄 + * @author widyhu + * + */ +class WxPayOrderQuery extends WxPayDataBase +{ + /** + * 璁剧疆寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D + * @param string $value + **/ + public function SetAppid($value) + { + $this->values['appid'] = $value; + } + /** + * 鑾峰彇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鐨勫 + * @return 鍊 + **/ + public function GetAppid() + { + return $this->values['appid']; + } + /** + * 鍒ゆ柇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsAppidSet() + { + return array_key_exists('appid', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿 + * @param string $value + **/ + public function SetMch_id($value) + { + $this->values['mch_id'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鐨勫 + * @return 鍊 + **/ + public function GetMch_id() + { + return $this->values['mch_id']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsMch_idSet() + { + return array_key_exists('mch_id', $this->values); + } + + + /** + * 璁剧疆寰俊鐨勮鍗曞彿锛屼紭鍏堜娇鐢 + * @param string $value + **/ + public function SetTransaction_id($value) + { + $this->values['transaction_id'] = $value; + } + /** + * 鑾峰彇寰俊鐨勮鍗曞彿锛屼紭鍏堜娇鐢ㄧ殑鍊 + * @return 鍊 + **/ + public function GetTransaction_id() + { + return $this->values['transaction_id']; + } + /** + * 鍒ゆ柇寰俊鐨勮鍗曞彿锛屼紭鍏堜娇鐢ㄦ槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsTransaction_idSet() + { + return array_key_exists('transaction_id', $this->values); + } + + + /** + * 璁剧疆鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿锛屽綋娌℃彁渚泃ransaction_id鏃堕渶瑕佷紶杩欎釜銆 + * @param string $value + **/ + public function SetOut_trade_no($value) + { + $this->values['out_trade_no'] = $value; + } + /** + * 鑾峰彇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿锛屽綋娌℃彁渚泃ransaction_id鏃堕渶瑕佷紶杩欎釜銆傜殑鍊 + * @return 鍊 + **/ + public function GetOut_trade_no() + { + return $this->values['out_trade_no']; + } + /** + * 鍒ゆ柇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿锛屽綋娌℃彁渚泃ransaction_id鏃堕渶瑕佷紶杩欎釜銆傛槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsOut_trade_noSet() + { + return array_key_exists('out_trade_no', $this->values); + } + + + /** + * 璁剧疆闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶 + * @param string $value + **/ + public function SetNonce_str($value) + { + $this->values['nonce_str'] = $value; + } + /** + * 鑾峰彇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鐨勫 + * @return 鍊 + **/ + public function GetNonce_str() + { + return $this->values['nonce_str']; + } + /** + * 鍒ゆ柇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsNonce_strSet() + { + return array_key_exists('nonce_str', $this->values); + } +} + +/** + * + * 鍏抽棴璁㈠崟杈撳叆瀵硅薄 + * @author widyhu + * + */ +class WxPayCloseOrder extends WxPayDataBase +{ + /** + * 璁剧疆寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D + * @param string $value + **/ + public function SetAppid($value) + { + $this->values['appid'] = $value; + } + /** + * 鑾峰彇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鐨勫 + * @return 鍊 + **/ + public function GetAppid() + { + return $this->values['appid']; + } + /** + * 鍒ゆ柇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsAppidSet() + { + return array_key_exists('appid', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿 + * @param string $value + **/ + public function SetMch_id($value) + { + $this->values['mch_id'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鐨勫 + * @return 鍊 + **/ + public function GetMch_id() + { + return $this->values['mch_id']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsMch_idSet() + { + return array_key_exists('mch_id', $this->values); + } + + + /** + * 璁剧疆鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿 + * @param string $value + **/ + public function SetOut_trade_no($value) + { + $this->values['out_trade_no'] = $value; + } + /** + * 鑾峰彇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿鐨勫 + * @return 鍊 + **/ + public function GetOut_trade_no() + { + return $this->values['out_trade_no']; + } + /** + * 鍒ゆ柇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsOut_trade_noSet() + { + return array_key_exists('out_trade_no', $this->values); + } + + + /** + * 璁剧疆鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,32涓瓧绗﹀唴銆佸彲鍖呭惈瀛楁瘝, 鍏朵粬璇存槑瑙佸晢鎴疯鍗曞彿 + * @param string $value + **/ + public function SetNonce_str($value) + { + $this->values['nonce_str'] = $value; + } + /** + * 鑾峰彇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,32涓瓧绗﹀唴銆佸彲鍖呭惈瀛楁瘝, 鍏朵粬璇存槑瑙佸晢鎴疯鍗曞彿鐨勫 + * @return 鍊 + **/ + public function GetNonce_str() + { + return $this->values['nonce_str']; + } + /** + * 鍒ゆ柇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,32涓瓧绗﹀唴銆佸彲鍖呭惈瀛楁瘝, 鍏朵粬璇存槑瑙佸晢鎴疯鍗曞彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsNonce_strSet() + { + return array_key_exists('nonce_str', $this->values); + } +} + +/** + * + * 鎻愪氦閫娆捐緭鍏ュ璞 + * @author widyhu + * + */ +class WxPayRefund extends WxPayDataBase +{ + /** + * 璁剧疆寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D + * @param string $value + **/ + public function SetAppid($value) + { + $this->values['appid'] = $value; + } + /** + * 鑾峰彇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鐨勫 + * @return 鍊 + **/ + public function GetAppid() + { + return $this->values['appid']; + } + /** + * 鍒ゆ柇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsAppidSet() + { + return array_key_exists('appid', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿 + * @param string $value + **/ + public function SetMch_id($value) + { + $this->values['mch_id'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鐨勫 + * @return 鍊 + **/ + public function GetMch_id() + { + return $this->values['mch_id']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsMch_idSet() + { + return array_key_exists('mch_id', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勭粓绔澶囧彿锛屼笌涓嬪崟涓鑷 + * @param string $value + **/ + public function SetDevice_info($value) + { + $this->values['device_info'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勭粓绔澶囧彿锛屼笌涓嬪崟涓鑷寸殑鍊 + * @return 鍊 + **/ + public function GetDevice_info() + { + return $this->values['device_info']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勭粓绔澶囧彿锛屼笌涓嬪崟涓鑷存槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsDevice_infoSet() + { + return array_key_exists('device_info', $this->values); + } + + + /** + * 璁剧疆闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶 + * @param string $value + **/ + public function SetNonce_str($value) + { + $this->values['nonce_str'] = $value; + } + /** + * 鑾峰彇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鐨勫 + * @return 鍊 + **/ + public function GetNonce_str() + { + return $this->values['nonce_str']; + } + /** + * 鍒ゆ柇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsNonce_strSet() + { + return array_key_exists('nonce_str', $this->values); + } + + /** + * 璁剧疆寰俊璁㈠崟鍙 + * @param string $value + **/ + public function SetTransaction_id($value) + { + $this->values['transaction_id'] = $value; + } + /** + * 鑾峰彇寰俊璁㈠崟鍙风殑鍊 + * @return 鍊 + **/ + public function GetTransaction_id() + { + return $this->values['transaction_id']; + } + /** + * 鍒ゆ柇寰俊璁㈠崟鍙锋槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsTransaction_idSet() + { + return array_key_exists('transaction_id', $this->values); + } + + + /** + * 璁剧疆鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,transaction_id銆乷ut_trade_no浜岄変竴锛屽鏋滃悓鏃跺瓨鍦ㄤ紭鍏堢骇锛歵ransaction_id> out_trade_no + * @param string $value + **/ + public function SetOut_trade_no($value) + { + $this->values['out_trade_no'] = $value; + } + /** + * 鑾峰彇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,transaction_id銆乷ut_trade_no浜岄変竴锛屽鏋滃悓鏃跺瓨鍦ㄤ紭鍏堢骇锛歵ransaction_id> out_trade_no鐨勫 + * @return 鍊 + **/ + public function GetOut_trade_no() + { + return $this->values['out_trade_no']; + } + /** + * 鍒ゆ柇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,transaction_id銆乷ut_trade_no浜岄変竴锛屽鏋滃悓鏃跺瓨鍦ㄤ紭鍏堢骇锛歵ransaction_id> out_trade_no鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsOut_trade_noSet() + { + return array_key_exists('out_trade_no', $this->values); + } + + + /** + * 璁剧疆鍟嗘埛绯荤粺鍐呴儴鐨勯娆惧崟鍙凤紝鍟嗘埛绯荤粺鍐呴儴鍞竴锛屽悓涓閫娆惧崟鍙峰娆¤姹傚彧閫涓绗 + * @param string $value + **/ + public function SetOut_refund_no($value) + { + $this->values['out_refund_no'] = $value; + } + /** + * 鑾峰彇鍟嗘埛绯荤粺鍐呴儴鐨勯娆惧崟鍙凤紝鍟嗘埛绯荤粺鍐呴儴鍞竴锛屽悓涓閫娆惧崟鍙峰娆¤姹傚彧閫涓绗旂殑鍊 + * @return 鍊 + **/ + public function GetOut_refund_no() + { + return $this->values['out_refund_no']; + } + /** + * 鍒ゆ柇鍟嗘埛绯荤粺鍐呴儴鐨勯娆惧崟鍙凤紝鍟嗘埛绯荤粺鍐呴儴鍞竴锛屽悓涓閫娆惧崟鍙峰娆¤姹傚彧閫涓绗旀槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsOut_refund_noSet() + { + return array_key_exists('out_refund_no', $this->values); + } + + + /** + * 璁剧疆璁㈠崟鎬婚噾棰濓紝鍗曚綅涓哄垎锛屽彧鑳戒负鏁存暟锛岃瑙佹敮浠橀噾棰 + * @param string $value + **/ + public function SetTotal_fee($value) + { + $this->values['total_fee'] = $value; + } + /** + * 鑾峰彇璁㈠崟鎬婚噾棰濓紝鍗曚綅涓哄垎锛屽彧鑳戒负鏁存暟锛岃瑙佹敮浠橀噾棰濈殑鍊 + * @return 鍊 + **/ + public function GetTotal_fee() + { + return $this->values['total_fee']; + } + /** + * 鍒ゆ柇璁㈠崟鎬婚噾棰濓紝鍗曚綅涓哄垎锛屽彧鑳戒负鏁存暟锛岃瑙佹敮浠橀噾棰濇槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsTotal_feeSet() + { + return array_key_exists('total_fee', $this->values); + } + + + /** + * 璁剧疆閫娆炬婚噾棰濓紝璁㈠崟鎬婚噾棰濓紝鍗曚綅涓哄垎锛屽彧鑳戒负鏁存暟锛岃瑙佹敮浠橀噾棰 + * @param string $value + **/ + public function SetRefund_fee($value) + { + $this->values['refund_fee'] = $value; + } + /** + * 鑾峰彇閫娆炬婚噾棰濓紝璁㈠崟鎬婚噾棰濓紝鍗曚綅涓哄垎锛屽彧鑳戒负鏁存暟锛岃瑙佹敮浠橀噾棰濈殑鍊 + * @return 鍊 + **/ + public function GetRefund_fee() + { + return $this->values['refund_fee']; + } + /** + * 鍒ゆ柇閫娆炬婚噾棰濓紝璁㈠崟鎬婚噾棰濓紝鍗曚綅涓哄垎锛屽彧鑳戒负鏁存暟锛岃瑙佹敮浠橀噾棰濇槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsRefund_feeSet() + { + return array_key_exists('refund_fee', $this->values); + } + + + /** + * 璁剧疆璐у竵绫诲瀷锛岀鍚圛SO 4217鏍囧噯鐨勪笁浣嶅瓧姣嶄唬鐮侊紝榛樿浜烘皯甯侊細CNY锛屽叾浠栧煎垪琛ㄨ瑙佽揣甯佺被鍨 + * @param string $value + **/ + public function SetRefund_fee_type($value) + { + $this->values['refund_fee_type'] = $value; + } + /** + * 鑾峰彇璐у竵绫诲瀷锛岀鍚圛SO 4217鏍囧噯鐨勪笁浣嶅瓧姣嶄唬鐮侊紝榛樿浜烘皯甯侊細CNY锛屽叾浠栧煎垪琛ㄨ瑙佽揣甯佺被鍨嬬殑鍊 + * @return 鍊 + **/ + public function GetRefund_fee_type() + { + return $this->values['refund_fee_type']; + } + /** + * 鍒ゆ柇璐у竵绫诲瀷锛岀鍚圛SO 4217鏍囧噯鐨勪笁浣嶅瓧姣嶄唬鐮侊紝榛樿浜烘皯甯侊細CNY锛屽叾浠栧煎垪琛ㄨ瑙佽揣甯佺被鍨嬫槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsRefund_fee_typeSet() + { + return array_key_exists('refund_fee_type', $this->values); + } + + + /** + * 璁剧疆鎿嶄綔鍛樺笎鍙, 榛樿涓哄晢鎴峰彿 + * @param string $value + **/ + public function SetOp_user_id($value) + { + $this->values['op_user_id'] = $value; + } + /** + * 鑾峰彇鎿嶄綔鍛樺笎鍙, 榛樿涓哄晢鎴峰彿鐨勫 + * @return 鍊 + **/ + public function GetOp_user_id() + { + return $this->values['op_user_id']; + } + /** + * 鍒ゆ柇鎿嶄綔鍛樺笎鍙, 榛樿涓哄晢鎴峰彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsOp_user_idSet() + { + return array_key_exists('op_user_id', $this->values); + } +} + +/** + * + * 閫娆炬煡璇㈣緭鍏ュ璞 + * @author widyhu + * + */ +class WxPayRefundQuery extends WxPayDataBase +{ + /** + * 璁剧疆寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D + * @param string $value + **/ + public function SetAppid($value) + { + $this->values['appid'] = $value; + } + /** + * 鑾峰彇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鐨勫 + * @return 鍊 + **/ + public function GetAppid() + { + return $this->values['appid']; + } + /** + * 鍒ゆ柇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsAppidSet() + { + return array_key_exists('appid', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿 + * @param string $value + **/ + public function SetMch_id($value) + { + $this->values['mch_id'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鐨勫 + * @return 鍊 + **/ + public function GetMch_id() + { + return $this->values['mch_id']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsMch_idSet() + { + return array_key_exists('mch_id', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勭粓绔澶囧彿 + * @param string $value + **/ + public function SetDevice_info($value) + { + $this->values['device_info'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勭粓绔澶囧彿鐨勫 + * @return 鍊 + **/ + public function GetDevice_info() + { + return $this->values['device_info']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勭粓绔澶囧彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsDevice_infoSet() + { + return array_key_exists('device_info', $this->values); + } + + + /** + * 璁剧疆闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶 + * @param string $value + **/ + public function SetNonce_str($value) + { + $this->values['nonce_str'] = $value; + } + /** + * 鑾峰彇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鐨勫 + * @return 鍊 + **/ + public function GetNonce_str() + { + return $this->values['nonce_str']; + } + /** + * 鍒ゆ柇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsNonce_strSet() + { + return array_key_exists('nonce_str', $this->values); + } + + /** + * 璁剧疆寰俊璁㈠崟鍙 + * @param string $value + **/ + public function SetTransaction_id($value) + { + $this->values['transaction_id'] = $value; + } + /** + * 鑾峰彇寰俊璁㈠崟鍙风殑鍊 + * @return 鍊 + **/ + public function GetTransaction_id() + { + return $this->values['transaction_id']; + } + /** + * 鍒ゆ柇寰俊璁㈠崟鍙锋槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsTransaction_idSet() + { + return array_key_exists('transaction_id', $this->values); + } + + + /** + * 璁剧疆鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿 + * @param string $value + **/ + public function SetOut_trade_no($value) + { + $this->values['out_trade_no'] = $value; + } + /** + * 鑾峰彇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿鐨勫 + * @return 鍊 + **/ + public function GetOut_trade_no() + { + return $this->values['out_trade_no']; + } + /** + * 鍒ゆ柇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsOut_trade_noSet() + { + return array_key_exists('out_trade_no', $this->values); + } + + + /** + * 璁剧疆鍟嗘埛閫娆惧崟鍙 + * @param string $value + **/ + public function SetOut_refund_no($value) + { + $this->values['out_refund_no'] = $value; + } + /** + * 鑾峰彇鍟嗘埛閫娆惧崟鍙风殑鍊 + * @return 鍊 + **/ + public function GetOut_refund_no() + { + return $this->values['out_refund_no']; + } + /** + * 鍒ゆ柇鍟嗘埛閫娆惧崟鍙锋槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsOut_refund_noSet() + { + return array_key_exists('out_refund_no', $this->values); + } + + + /** + * 璁剧疆寰俊閫娆惧崟鍙穜efund_id銆乷ut_refund_no銆乷ut_trade_no銆乼ransaction_id鍥涗釜鍙傛暟蹇呭~涓涓紝濡傛灉鍚屾椂瀛樺湪浼樺厛绾т负锛歳efund_id>out_refund_no>transaction_id>out_trade_no + * @param string $value + **/ + public function SetRefund_id($value) + { + $this->values['refund_id'] = $value; + } + /** + * 鑾峰彇寰俊閫娆惧崟鍙穜efund_id銆乷ut_refund_no銆乷ut_trade_no銆乼ransaction_id鍥涗釜鍙傛暟蹇呭~涓涓紝濡傛灉鍚屾椂瀛樺湪浼樺厛绾т负锛歳efund_id>out_refund_no>transaction_id>out_trade_no鐨勫 + * @return 鍊 + **/ + public function GetRefund_id() + { + return $this->values['refund_id']; + } + /** + * 鍒ゆ柇寰俊閫娆惧崟鍙穜efund_id銆乷ut_refund_no銆乷ut_trade_no銆乼ransaction_id鍥涗釜鍙傛暟蹇呭~涓涓紝濡傛灉鍚屾椂瀛樺湪浼樺厛绾т负锛歳efund_id>out_refund_no>transaction_id>out_trade_no鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsRefund_idSet() + { + return array_key_exists('refund_id', $this->values); + } +} + +/** + * + * 涓嬭浇瀵硅处鍗曡緭鍏ュ璞 + * @author widyhu + * + */ +class WxPayDownloadBill extends WxPayDataBase +{ + /** + * 璁剧疆寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D + * @param string $value + **/ + public function SetAppid($value) + { + $this->values['appid'] = $value; + } + /** + * 鑾峰彇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鐨勫 + * @return 鍊 + **/ + public function GetAppid() + { + return $this->values['appid']; + } + /** + * 鍒ゆ柇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsAppidSet() + { + return array_key_exists('appid', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿 + * @param string $value + **/ + public function SetMch_id($value) + { + $this->values['mch_id'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鐨勫 + * @return 鍊 + **/ + public function GetMch_id() + { + return $this->values['mch_id']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsMch_idSet() + { + return array_key_exists('mch_id', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勭粓绔澶囧彿锛屽~鍐欐瀛楁锛屽彧涓嬭浇璇ヨ澶囧彿鐨勫璐﹀崟 + * @param string $value + **/ + public function SetDevice_info($value) + { + $this->values['device_info'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勭粓绔澶囧彿锛屽~鍐欐瀛楁锛屽彧涓嬭浇璇ヨ澶囧彿鐨勫璐﹀崟鐨勫 + * @return 鍊 + **/ + public function GetDevice_info() + { + return $this->values['device_info']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勭粓绔澶囧彿锛屽~鍐欐瀛楁锛屽彧涓嬭浇璇ヨ澶囧彿鐨勫璐﹀崟鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsDevice_infoSet() + { + return array_key_exists('device_info', $this->values); + } + + + /** + * 璁剧疆闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶 + * @param string $value + **/ + public function SetNonce_str($value) + { + $this->values['nonce_str'] = $value; + } + /** + * 鑾峰彇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鐨勫 + * @return 鍊 + **/ + public function GetNonce_str() + { + return $this->values['nonce_str']; + } + /** + * 鍒ゆ柇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsNonce_strSet() + { + return array_key_exists('nonce_str', $this->values); + } + + /** + * 璁剧疆涓嬭浇瀵硅处鍗曠殑鏃ユ湡锛屾牸寮忥細20140603 + * @param string $value + **/ + public function SetBill_date($value) + { + $this->values['bill_date'] = $value; + } + /** + * 鑾峰彇涓嬭浇瀵硅处鍗曠殑鏃ユ湡锛屾牸寮忥細20140603鐨勫 + * @return 鍊 + **/ + public function GetBill_date() + { + return $this->values['bill_date']; + } + /** + * 鍒ゆ柇涓嬭浇瀵硅处鍗曠殑鏃ユ湡锛屾牸寮忥細20140603鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsBill_dateSet() + { + return array_key_exists('bill_date', $this->values); + } + + + /** + * 璁剧疆ALL锛岃繑鍥炲綋鏃ユ墍鏈夎鍗曚俊鎭紝榛樿鍊糞UCCESS锛岃繑鍥炲綋鏃ユ垚鍔熸敮浠樼殑璁㈠崟REFUND锛岃繑鍥炲綋鏃ラ娆捐鍗昍EVOKED锛屽凡鎾ら攢鐨勮鍗 + * @param string $value + **/ + public function SetBill_type($value) + { + $this->values['bill_type'] = $value; + } + /** + * 鑾峰彇ALL锛岃繑鍥炲綋鏃ユ墍鏈夎鍗曚俊鎭紝榛樿鍊糞UCCESS锛岃繑鍥炲綋鏃ユ垚鍔熸敮浠樼殑璁㈠崟REFUND锛岃繑鍥炲綋鏃ラ娆捐鍗昍EVOKED锛屽凡鎾ら攢鐨勮鍗曠殑鍊 + * @return 鍊 + **/ + public function GetBill_type() + { + return $this->values['bill_type']; + } + /** + * 鍒ゆ柇ALL锛岃繑鍥炲綋鏃ユ墍鏈夎鍗曚俊鎭紝榛樿鍊糞UCCESS锛岃繑鍥炲綋鏃ユ垚鍔熸敮浠樼殑璁㈠崟REFUND锛岃繑鍥炲綋鏃ラ娆捐鍗昍EVOKED锛屽凡鎾ら攢鐨勮鍗曟槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsBill_typeSet() + { + return array_key_exists('bill_type', $this->values); + } +} + +/** + * + * 娴嬮熶笂鎶ヨ緭鍏ュ璞 + * @author widyhu + * + */ +class WxPayReport extends WxPayDataBase +{ + /** + * 璁剧疆寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D + * @param string $value + **/ + public function SetAppid($value) + { + $this->values['appid'] = $value; + } + /** + * 鑾峰彇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鐨勫 + * @return 鍊 + **/ + public function GetAppid() + { + return $this->values['appid']; + } + /** + * 鍒ゆ柇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsAppidSet() + { + return array_key_exists('appid', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿 + * @param string $value + **/ + public function SetMch_id($value) + { + $this->values['mch_id'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鐨勫 + * @return 鍊 + **/ + public function GetMch_id() + { + return $this->values['mch_id']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsMch_idSet() + { + return array_key_exists('mch_id', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勭粓绔澶囧彿锛屽晢鎴疯嚜瀹氫箟 + * @param string $value + **/ + public function SetDevice_info($value) + { + $this->values['device_info'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勭粓绔澶囧彿锛屽晢鎴疯嚜瀹氫箟鐨勫 + * @return 鍊 + **/ + public function GetDevice_info() + { + return $this->values['device_info']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勭粓绔澶囧彿锛屽晢鎴疯嚜瀹氫箟鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsDevice_infoSet() + { + return array_key_exists('device_info', $this->values); + } + + + /** + * 璁剧疆闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶 + * @param string $value + **/ + public function SetNonce_str($value) + { + $this->values['nonce_str'] = $value; + } + /** + * 鑾峰彇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鐨勫 + * @return 鍊 + **/ + public function GetNonce_str() + { + return $this->values['nonce_str']; + } + /** + * 鍒ゆ柇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsNonce_strSet() + { + return array_key_exists('nonce_str', $this->values); + } + + + /** + * 璁剧疆涓婃姤瀵瑰簲鐨勬帴鍙g殑瀹屾暣URL锛岀被浼硷細https://api.mch.weixin.qq.com/pay/unifiedorder瀵逛簬琚壂鏀粯锛屼负鏇村ソ鐨勫拰鍟嗘埛鍏卞悓鍒嗘瀽涓娆′笟鍔¤涓虹殑鏁翠綋鑰楁椂鎯呭喌锛屽浜庝袱绉嶆帴鍏ユā寮忥紝璇烽兘鍦ㄩ棬搴椾晶瀵逛竴娆¤鎵涓鸿繘琛屼竴娆″崟鐙殑鏁翠綋涓婃姤锛屼笂鎶RL鎸囧畾涓猴細https://api.mch.weixin.qq.com/pay/micropay/total鍏充簬涓ょ鎺ュ叆妯″紡鍏蜂綋鍙弬鑰冩湰鏂囨。绔犺妭锛氳鎵敮浠樺晢鎴锋帴鍏ユā寮忓叾瀹冩帴鍙h皟鐢ㄤ粛鐒舵寜鐓ц皟鐢ㄤ竴娆★紝涓婃姤涓娆℃潵杩涜銆 + * @param string $value + **/ + public function SetInterface_url($value) + { + $this->values['interface_url'] = $value; + } + /** + * 鑾峰彇涓婃姤瀵瑰簲鐨勬帴鍙g殑瀹屾暣URL锛岀被浼硷細https://api.mch.weixin.qq.com/pay/unifiedorder瀵逛簬琚壂鏀粯锛屼负鏇村ソ鐨勫拰鍟嗘埛鍏卞悓鍒嗘瀽涓娆′笟鍔¤涓虹殑鏁翠綋鑰楁椂鎯呭喌锛屽浜庝袱绉嶆帴鍏ユā寮忥紝璇烽兘鍦ㄩ棬搴椾晶瀵逛竴娆¤鎵涓鸿繘琛屼竴娆″崟鐙殑鏁翠綋涓婃姤锛屼笂鎶RL鎸囧畾涓猴細https://api.mch.weixin.qq.com/pay/micropay/total鍏充簬涓ょ鎺ュ叆妯″紡鍏蜂綋鍙弬鑰冩湰鏂囨。绔犺妭锛氳鎵敮浠樺晢鎴锋帴鍏ユā寮忓叾瀹冩帴鍙h皟鐢ㄤ粛鐒舵寜鐓ц皟鐢ㄤ竴娆★紝涓婃姤涓娆℃潵杩涜銆傜殑鍊 + * @return 鍊 + **/ + public function GetInterface_url() + { + return $this->values['interface_url']; + } + /** + * 鍒ゆ柇涓婃姤瀵瑰簲鐨勬帴鍙g殑瀹屾暣URL锛岀被浼硷細https://api.mch.weixin.qq.com/pay/unifiedorder瀵逛簬琚壂鏀粯锛屼负鏇村ソ鐨勫拰鍟嗘埛鍏卞悓鍒嗘瀽涓娆′笟鍔¤涓虹殑鏁翠綋鑰楁椂鎯呭喌锛屽浜庝袱绉嶆帴鍏ユā寮忥紝璇烽兘鍦ㄩ棬搴椾晶瀵逛竴娆¤鎵涓鸿繘琛屼竴娆″崟鐙殑鏁翠綋涓婃姤锛屼笂鎶RL鎸囧畾涓猴細https://api.mch.weixin.qq.com/pay/micropay/total鍏充簬涓ょ鎺ュ叆妯″紡鍏蜂綋鍙弬鑰冩湰鏂囨。绔犺妭锛氳鎵敮浠樺晢鎴锋帴鍏ユā寮忓叾瀹冩帴鍙h皟鐢ㄤ粛鐒舵寜鐓ц皟鐢ㄤ竴娆★紝涓婃姤涓娆℃潵杩涜銆傛槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsInterface_urlSet() + { + return array_key_exists('interface_url', $this->values); + } + + + /** + * 璁剧疆鎺ュ彛鑰楁椂鎯呭喌锛屽崟浣嶄负姣 + * @param string $value + **/ + public function SetExecute_time_($value) + { + $this->values['execute_time_'] = $value; + } + /** + * 鑾峰彇鎺ュ彛鑰楁椂鎯呭喌锛屽崟浣嶄负姣鐨勫 + * @return 鍊 + **/ + public function GetExecute_time_() + { + return $this->values['execute_time_']; + } + /** + * 鍒ゆ柇鎺ュ彛鑰楁椂鎯呭喌锛屽崟浣嶄负姣鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsExecute_time_Set() + { + return array_key_exists('execute_time_', $this->values); + } + + + /** + * 璁剧疆SUCCESS/FAIL姝ゅ瓧娈垫槸閫氫俊鏍囪瘑锛岄潪浜ゆ槗鏍囪瘑锛屼氦鏄撴槸鍚︽垚鍔熼渶瑕佹煡鐪媡rade_state鏉ュ垽鏂 + * @param string $value + **/ + public function SetReturn_code($value) + { + $this->values['return_code'] = $value; + } + /** + * 鑾峰彇SUCCESS/FAIL姝ゅ瓧娈垫槸閫氫俊鏍囪瘑锛岄潪浜ゆ槗鏍囪瘑锛屼氦鏄撴槸鍚︽垚鍔熼渶瑕佹煡鐪媡rade_state鏉ュ垽鏂殑鍊 + * @return 鍊 + **/ + public function GetReturn_code() + { + return $this->values['return_code']; + } + /** + * 鍒ゆ柇SUCCESS/FAIL姝ゅ瓧娈垫槸閫氫俊鏍囪瘑锛岄潪浜ゆ槗鏍囪瘑锛屼氦鏄撴槸鍚︽垚鍔熼渶瑕佹煡鐪媡rade_state鏉ュ垽鏂槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsReturn_codeSet() + { + return array_key_exists('return_code', $this->values); + } + + + /** + * 璁剧疆杩斿洖淇℃伅锛屽闈炵┖锛屼负閿欒鍘熷洜绛惧悕澶辫触鍙傛暟鏍煎紡鏍¢獙閿欒 + * @param string $value + **/ + public function SetReturn_msg($value) + { + $this->values['return_msg'] = $value; + } + /** + * 鑾峰彇杩斿洖淇℃伅锛屽闈炵┖锛屼负閿欒鍘熷洜绛惧悕澶辫触鍙傛暟鏍煎紡鏍¢獙閿欒鐨勫 + * @return 鍊 + **/ + public function GetReturn_msg() + { + return $this->values['return_msg']; + } + /** + * 鍒ゆ柇杩斿洖淇℃伅锛屽闈炵┖锛屼负閿欒鍘熷洜绛惧悕澶辫触鍙傛暟鏍煎紡鏍¢獙閿欒鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsReturn_msgSet() + { + return array_key_exists('return_msg', $this->values); + } + + + /** + * 璁剧疆SUCCESS/FAIL + * @param string $value + **/ + public function SetResult_code($value) + { + $this->values['result_code'] = $value; + } + /** + * 鑾峰彇SUCCESS/FAIL鐨勫 + * @return 鍊 + **/ + public function GetResult_code() + { + return $this->values['result_code']; + } + /** + * 鍒ゆ柇SUCCESS/FAIL鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsResult_codeSet() + { + return array_key_exists('result_code', $this->values); + } + + + /** + * 璁剧疆ORDERNOTEXIST鈥旇鍗曚笉瀛樺湪SYSTEMERROR鈥旂郴缁熼敊璇 + * @param string $value + **/ + public function SetErr_code($value) + { + $this->values['err_code'] = $value; + } + /** + * 鑾峰彇ORDERNOTEXIST鈥旇鍗曚笉瀛樺湪SYSTEMERROR鈥旂郴缁熼敊璇殑鍊 + * @return 鍊 + **/ + public function GetErr_code() + { + return $this->values['err_code']; + } + /** + * 鍒ゆ柇ORDERNOTEXIST鈥旇鍗曚笉瀛樺湪SYSTEMERROR鈥旂郴缁熼敊璇槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsErr_codeSet() + { + return array_key_exists('err_code', $this->values); + } + + + /** + * 璁剧疆缁撴灉淇℃伅鎻忚堪 + * @param string $value + **/ + public function SetErr_code_des($value) + { + $this->values['err_code_des'] = $value; + } + /** + * 鑾峰彇缁撴灉淇℃伅鎻忚堪鐨勫 + * @return 鍊 + **/ + public function GetErr_code_des() + { + return $this->values['err_code_des']; + } + /** + * 鍒ゆ柇缁撴灉淇℃伅鎻忚堪鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsErr_code_desSet() + { + return array_key_exists('err_code_des', $this->values); + } + + + /** + * 璁剧疆鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,鍟嗘埛鍙互鍦ㄤ笂鎶ユ椂鎻愪緵鐩稿叧鍟嗘埛璁㈠崟鍙锋柟渚垮井淇℃敮浠樻洿濂界殑鎻愰珮鏈嶅姟璐ㄩ噺銆 + * @param string $value + **/ + public function SetOut_trade_no($value) + { + $this->values['out_trade_no'] = $value; + } + /** + * 鑾峰彇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,鍟嗘埛鍙互鍦ㄤ笂鎶ユ椂鎻愪緵鐩稿叧鍟嗘埛璁㈠崟鍙锋柟渚垮井淇℃敮浠樻洿濂界殑鎻愰珮鏈嶅姟璐ㄩ噺銆 鐨勫 + * @return 鍊 + **/ + public function GetOut_trade_no() + { + return $this->values['out_trade_no']; + } + /** + * 鍒ゆ柇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,鍟嗘埛鍙互鍦ㄤ笂鎶ユ椂鎻愪緵鐩稿叧鍟嗘埛璁㈠崟鍙锋柟渚垮井淇℃敮浠樻洿濂界殑鎻愰珮鏈嶅姟璐ㄩ噺銆 鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsOut_trade_noSet() + { + return array_key_exists('out_trade_no', $this->values); + } + + + /** + * 璁剧疆鍙戣捣鎺ュ彛璋冪敤鏃剁殑鏈哄櫒IP + * @param string $value + **/ + public function SetUser_ip($value) + { + $this->values['user_ip'] = $value; + } + /** + * 鑾峰彇鍙戣捣鎺ュ彛璋冪敤鏃剁殑鏈哄櫒IP 鐨勫 + * @return 鍊 + **/ + public function GetUser_ip() + { + return $this->values['user_ip']; + } + /** + * 鍒ゆ柇鍙戣捣鎺ュ彛璋冪敤鏃剁殑鏈哄櫒IP 鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsUser_ipSet() + { + return array_key_exists('user_ip', $this->values); + } + + + /** + * 璁剧疆绯荤粺鏃堕棿锛屾牸寮忎负yyyyMMddHHmmss锛屽2009骞12鏈27鏃9鐐10鍒10绉掕〃绀轰负20091227091010銆傚叾浠栬瑙佹椂闂磋鍒 + * @param string $value + **/ + public function SetTime($value) + { + $this->values['time'] = $value; + } + /** + * 鑾峰彇绯荤粺鏃堕棿锛屾牸寮忎负yyyyMMddHHmmss锛屽2009骞12鏈27鏃9鐐10鍒10绉掕〃绀轰负20091227091010銆傚叾浠栬瑙佹椂闂磋鍒欑殑鍊 + * @return 鍊 + **/ + public function GetTime() + { + return $this->values['time']; + } + /** + * 鍒ゆ柇绯荤粺鏃堕棿锛屾牸寮忎负yyyyMMddHHmmss锛屽2009骞12鏈27鏃9鐐10鍒10绉掕〃绀轰负20091227091010銆傚叾浠栬瑙佹椂闂磋鍒欐槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsTimeSet() + { + return array_key_exists('time', $this->values); + } +} + +/** + * + * 鐭摼杞崲杈撳叆瀵硅薄 + * @author widyhu + * + */ +class WxPayShortUrl extends WxPayDataBase +{ + /** + * 璁剧疆寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D + * @param string $value + **/ + public function SetAppid($value) + { + $this->values['appid'] = $value; + } + /** + * 鑾峰彇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鐨勫 + * @return 鍊 + **/ + public function GetAppid() + { + return $this->values['appid']; + } + /** + * 鍒ゆ柇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsAppidSet() + { + return array_key_exists('appid', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿 + * @param string $value + **/ + public function SetMch_id($value) + { + $this->values['mch_id'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鐨勫 + * @return 鍊 + **/ + public function GetMch_id() + { + return $this->values['mch_id']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsMch_idSet() + { + return array_key_exists('mch_id', $this->values); + } + + + /** + * 璁剧疆闇瑕佽浆鎹㈢殑URL锛岀鍚嶇敤鍘熶覆锛屼紶杈撻渶URL encode + * @param string $value + **/ + public function SetLong_url($value) + { + $this->values['long_url'] = $value; + } + /** + * 鑾峰彇闇瑕佽浆鎹㈢殑URL锛岀鍚嶇敤鍘熶覆锛屼紶杈撻渶URL encode鐨勫 + * @return 鍊 + **/ + public function GetLong_url() + { + return $this->values['long_url']; + } + /** + * 鍒ゆ柇闇瑕佽浆鎹㈢殑URL锛岀鍚嶇敤鍘熶覆锛屼紶杈撻渶URL encode鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsLong_urlSet() + { + return array_key_exists('long_url', $this->values); + } + + + /** + * 璁剧疆闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶 + * @param string $value + **/ + public function SetNonce_str($value) + { + $this->values['nonce_str'] = $value; + } + /** + * 鑾峰彇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鐨勫 + * @return 鍊 + **/ + public function GetNonce_str() + { + return $this->values['nonce_str']; + } + /** + * 鍒ゆ柇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsNonce_strSet() + { + return array_key_exists('nonce_str', $this->values); + } +} + +/** + * + * 鎻愪氦琚壂杈撳叆瀵硅薄 + * @author widyhu + * + */ +class WxPayMicroPay extends WxPayDataBase +{ + /** + * 璁剧疆寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D + * @param string $value + **/ + public function SetAppid($value) + { + $this->values['appid'] = $value; + } + /** + * 鑾峰彇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鐨勫 + * @return 鍊 + **/ + public function GetAppid() + { + return $this->values['appid']; + } + /** + * 鍒ゆ柇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsAppidSet() + { + return array_key_exists('appid', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿 + * @param string $value + **/ + public function SetMch_id($value) + { + $this->values['mch_id'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鐨勫 + * @return 鍊 + **/ + public function GetMch_id() + { + return $this->values['mch_id']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsMch_idSet() + { + return array_key_exists('mch_id', $this->values); + } + + + /** + * 璁剧疆缁堢璁惧鍙(鍟嗘埛鑷畾涔夛紝濡傞棬搴楃紪鍙) + * @param string $value + **/ + public function SetDevice_info($value) + { + $this->values['device_info'] = $value; + } + /** + * 鑾峰彇缁堢璁惧鍙(鍟嗘埛鑷畾涔夛紝濡傞棬搴楃紪鍙)鐨勫 + * @return 鍊 + **/ + public function GetDevice_info() + { + return $this->values['device_info']; + } + /** + * 鍒ゆ柇缁堢璁惧鍙(鍟嗘埛鑷畾涔夛紝濡傞棬搴楃紪鍙)鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsDevice_infoSet() + { + return array_key_exists('device_info', $this->values); + } + + + /** + * 璁剧疆闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶 + * @param string $value + **/ + public function SetNonce_str($value) + { + $this->values['nonce_str'] = $value; + } + /** + * 鑾峰彇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鐨勫 + * @return 鍊 + **/ + public function GetNonce_str() + { + return $this->values['nonce_str']; + } + /** + * 鍒ゆ柇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsNonce_strSet() + { + return array_key_exists('nonce_str', $this->values); + } + + /** + * 璁剧疆鍟嗗搧鎴栨敮浠樺崟绠瑕佹弿杩 + * @param string $value + **/ + public function SetBody($value) + { + $this->values['body'] = $value; + } + /** + * 鑾峰彇鍟嗗搧鎴栨敮浠樺崟绠瑕佹弿杩扮殑鍊 + * @return 鍊 + **/ + public function GetBody() + { + return $this->values['body']; + } + /** + * 鍒ゆ柇鍟嗗搧鎴栨敮浠樺崟绠瑕佹弿杩版槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsBodySet() + { + return array_key_exists('body', $this->values); + } + + + /** + * 璁剧疆鍟嗗搧鍚嶇О鏄庣粏鍒楄〃 + * @param string $value + **/ + public function SetDetail($value) + { + $this->values['detail'] = $value; + } + /** + * 鑾峰彇鍟嗗搧鍚嶇О鏄庣粏鍒楄〃鐨勫 + * @return 鍊 + **/ + public function GetDetail() + { + return $this->values['detail']; + } + /** + * 鍒ゆ柇鍟嗗搧鍚嶇О鏄庣粏鍒楄〃鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsDetailSet() + { + return array_key_exists('detail', $this->values); + } + + + /** + * 璁剧疆闄勫姞鏁版嵁锛屽湪鏌ヨAPI鍜屾敮浠橀氱煡涓師鏍疯繑鍥烇紝璇ュ瓧娈典富瑕佺敤浜庡晢鎴锋惡甯﹁鍗曠殑鑷畾涔夋暟鎹 + * @param string $value + **/ + public function SetAttach($value) + { + $this->values['attach'] = $value; + } + /** + * 鑾峰彇闄勫姞鏁版嵁锛屽湪鏌ヨAPI鍜屾敮浠橀氱煡涓師鏍疯繑鍥烇紝璇ュ瓧娈典富瑕佺敤浜庡晢鎴锋惡甯﹁鍗曠殑鑷畾涔夋暟鎹殑鍊 + * @return 鍊 + **/ + public function GetAttach() + { + return $this->values['attach']; + } + /** + * 鍒ゆ柇闄勫姞鏁版嵁锛屽湪鏌ヨAPI鍜屾敮浠橀氱煡涓師鏍疯繑鍥烇紝璇ュ瓧娈典富瑕佺敤浜庡晢鎴锋惡甯﹁鍗曠殑鑷畾涔夋暟鎹槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsAttachSet() + { + return array_key_exists('attach', $this->values); + } + + + /** + * 璁剧疆鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,32涓瓧绗﹀唴銆佸彲鍖呭惈瀛楁瘝, 鍏朵粬璇存槑瑙佸晢鎴疯鍗曞彿 + * @param string $value + **/ + public function SetOut_trade_no($value) + { + $this->values['out_trade_no'] = $value; + } + /** + * 鑾峰彇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,32涓瓧绗﹀唴銆佸彲鍖呭惈瀛楁瘝, 鍏朵粬璇存槑瑙佸晢鎴疯鍗曞彿鐨勫 + * @return 鍊 + **/ + public function GetOut_trade_no() + { + return $this->values['out_trade_no']; + } + /** + * 鍒ゆ柇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,32涓瓧绗﹀唴銆佸彲鍖呭惈瀛楁瘝, 鍏朵粬璇存槑瑙佸晢鎴疯鍗曞彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsOut_trade_noSet() + { + return array_key_exists('out_trade_no', $this->values); + } + + + /** + * 璁剧疆璁㈠崟鎬婚噾棰濓紝鍗曚綅涓哄垎锛屽彧鑳戒负鏁存暟锛岃瑙佹敮浠橀噾棰 + * @param string $value + **/ + public function SetTotal_fee($value) + { + $this->values['total_fee'] = $value; + } + /** + * 鑾峰彇璁㈠崟鎬婚噾棰濓紝鍗曚綅涓哄垎锛屽彧鑳戒负鏁存暟锛岃瑙佹敮浠橀噾棰濈殑鍊 + * @return 鍊 + **/ + public function GetTotal_fee() + { + return $this->values['total_fee']; + } + /** + * 鍒ゆ柇璁㈠崟鎬婚噾棰濓紝鍗曚綅涓哄垎锛屽彧鑳戒负鏁存暟锛岃瑙佹敮浠橀噾棰濇槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsTotal_feeSet() + { + return array_key_exists('total_fee', $this->values); + } + + + /** + * 璁剧疆绗﹀悎ISO 4217鏍囧噯鐨勪笁浣嶅瓧姣嶄唬鐮侊紝榛樿浜烘皯甯侊細CNY锛屽叾浠栧煎垪琛ㄨ瑙佽揣甯佺被鍨 + * @param string $value + **/ + public function SetFee_type($value) + { + $this->values['fee_type'] = $value; + } + /** + * 鑾峰彇绗﹀悎ISO 4217鏍囧噯鐨勪笁浣嶅瓧姣嶄唬鐮侊紝榛樿浜烘皯甯侊細CNY锛屽叾浠栧煎垪琛ㄨ瑙佽揣甯佺被鍨嬬殑鍊 + * @return 鍊 + **/ + public function GetFee_type() + { + return $this->values['fee_type']; + } + /** + * 鍒ゆ柇绗﹀悎ISO 4217鏍囧噯鐨勪笁浣嶅瓧姣嶄唬鐮侊紝榛樿浜烘皯甯侊細CNY锛屽叾浠栧煎垪琛ㄨ瑙佽揣甯佺被鍨嬫槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsFee_typeSet() + { + return array_key_exists('fee_type', $this->values); + } + + + /** + * 璁剧疆璋冪敤寰俊鏀粯API鐨勬満鍣↖P + * @param string $value + **/ + public function SetSpbill_create_ip($value) + { + $this->values['spbill_create_ip'] = $value; + } + /** + * 鑾峰彇璋冪敤寰俊鏀粯API鐨勬満鍣↖P 鐨勫 + * @return 鍊 + **/ + public function GetSpbill_create_ip() + { + return $this->values['spbill_create_ip']; + } + /** + * 鍒ゆ柇璋冪敤寰俊鏀粯API鐨勬満鍣↖P 鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsSpbill_create_ipSet() + { + return array_key_exists('spbill_create_ip', $this->values); + } + + /** + * 璁剧疆璁㈠崟鐢熸垚鏃堕棿锛屾牸寮忎负yyyyMMddHHmmss锛屽2009骞12鏈25鏃9鐐10鍒10绉掕〃绀轰负20091225091010銆傝瑙佹椂闂磋鍒 + * @param string $value + **/ + public function SetTime_start($value) + { + $this->values['time_start'] = $value; + } + /** + * 鑾峰彇璁㈠崟鐢熸垚鏃堕棿锛屾牸寮忎负yyyyMMddHHmmss锛屽2009骞12鏈25鏃9鐐10鍒10绉掕〃绀轰负20091225091010銆傝瑙佹椂闂磋鍒欑殑鍊 + * @return 鍊 + **/ + public function GetTime_start() + { + return $this->values['time_start']; + } + /** + * 鍒ゆ柇璁㈠崟鐢熸垚鏃堕棿锛屾牸寮忎负yyyyMMddHHmmss锛屽2009骞12鏈25鏃9鐐10鍒10绉掕〃绀轰负20091225091010銆傝瑙佹椂闂磋鍒欐槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsTime_startSet() + { + return array_key_exists('time_start', $this->values); + } + + + /** + * 璁剧疆璁㈠崟澶辨晥鏃堕棿锛屾牸寮忎负yyyyMMddHHmmss锛屽2009骞12鏈27鏃9鐐10鍒10绉掕〃绀轰负20091227091010銆傝瑙佹椂闂磋鍒 + * @param string $value + **/ + public function SetTime_expire($value) + { + $this->values['time_expire'] = $value; + } + /** + * 鑾峰彇璁㈠崟澶辨晥鏃堕棿锛屾牸寮忎负yyyyMMddHHmmss锛屽2009骞12鏈27鏃9鐐10鍒10绉掕〃绀轰负20091227091010銆傝瑙佹椂闂磋鍒欑殑鍊 + * @return 鍊 + **/ + public function GetTime_expire() + { + return $this->values['time_expire']; + } + /** + * 鍒ゆ柇璁㈠崟澶辨晥鏃堕棿锛屾牸寮忎负yyyyMMddHHmmss锛屽2009骞12鏈27鏃9鐐10鍒10绉掕〃绀轰负20091227091010銆傝瑙佹椂闂磋鍒欐槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsTime_expireSet() + { + return array_key_exists('time_expire', $this->values); + } + + + /** + * 璁剧疆鍟嗗搧鏍囪锛屼唬閲戝埜鎴栫珛鍑忎紭鎯犲姛鑳界殑鍙傛暟锛岃鏄庤瑙佷唬閲戝埜鎴栫珛鍑忎紭鎯 + * @param string $value + **/ + public function SetGoods_tag($value) + { + $this->values['goods_tag'] = $value; + } + /** + * 鑾峰彇鍟嗗搧鏍囪锛屼唬閲戝埜鎴栫珛鍑忎紭鎯犲姛鑳界殑鍙傛暟锛岃鏄庤瑙佷唬閲戝埜鎴栫珛鍑忎紭鎯犵殑鍊 + * @return 鍊 + **/ + public function GetGoods_tag() + { + return $this->values['goods_tag']; + } + /** + * 鍒ゆ柇鍟嗗搧鏍囪锛屼唬閲戝埜鎴栫珛鍑忎紭鎯犲姛鑳界殑鍙傛暟锛岃鏄庤瑙佷唬閲戝埜鎴栫珛鍑忎紭鎯犳槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsGoods_tagSet() + { + return array_key_exists('goods_tag', $this->values); + } + + + /** + * 璁剧疆鎵爜鏀粯鎺堟潈鐮侊紝璁惧璇诲彇鐢ㄦ埛寰俊涓殑鏉$爜鎴栬呬簩缁寸爜淇℃伅 + * @param string $value + **/ + public function SetAuth_code($value) + { + $this->values['auth_code'] = $value; + } + /** + * 鑾峰彇鎵爜鏀粯鎺堟潈鐮侊紝璁惧璇诲彇鐢ㄦ埛寰俊涓殑鏉$爜鎴栬呬簩缁寸爜淇℃伅鐨勫 + * @return 鍊 + **/ + public function GetAuth_code() + { + return $this->values['auth_code']; + } + /** + * 鍒ゆ柇鎵爜鏀粯鎺堟潈鐮侊紝璁惧璇诲彇鐢ㄦ埛寰俊涓殑鏉$爜鎴栬呬簩缁寸爜淇℃伅鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsAuth_codeSet() + { + return array_key_exists('auth_code', $this->values); + } +} + +/** + * + * 鎾ら攢杈撳叆瀵硅薄 + * @author widyhu + * + */ +class WxPayReverse extends WxPayDataBase +{ + /** + * 璁剧疆寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D + * @param string $value + **/ + public function SetAppid($value) + { + $this->values['appid'] = $value; + } + /** + * 鑾峰彇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鐨勫 + * @return 鍊 + **/ + public function GetAppid() + { + return $this->values['appid']; + } + /** + * 鍒ゆ柇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsAppidSet() + { + return array_key_exists('appid', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿 + * @param string $value + **/ + public function SetMch_id($value) + { + $this->values['mch_id'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鐨勫 + * @return 鍊 + **/ + public function GetMch_id() + { + return $this->values['mch_id']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsMch_idSet() + { + return array_key_exists('mch_id', $this->values); + } + + + /** + * 璁剧疆寰俊鐨勮鍗曞彿锛屼紭鍏堜娇鐢 + * @param string $value + **/ + public function SetTransaction_id($value) + { + $this->values['transaction_id'] = $value; + } + /** + * 鑾峰彇寰俊鐨勮鍗曞彿锛屼紭鍏堜娇鐢ㄧ殑鍊 + * @return 鍊 + **/ + public function GetTransaction_id() + { + return $this->values['transaction_id']; + } + /** + * 鍒ゆ柇寰俊鐨勮鍗曞彿锛屼紭鍏堜娇鐢ㄦ槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsTransaction_idSet() + { + return array_key_exists('transaction_id', $this->values); + } + + + /** + * 璁剧疆鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,transaction_id銆乷ut_trade_no浜岄変竴锛屽鏋滃悓鏃跺瓨鍦ㄤ紭鍏堢骇锛歵ransaction_id> out_trade_no + * @param string $value + **/ + public function SetOut_trade_no($value) + { + $this->values['out_trade_no'] = $value; + } + /** + * 鑾峰彇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,transaction_id銆乷ut_trade_no浜岄変竴锛屽鏋滃悓鏃跺瓨鍦ㄤ紭鍏堢骇锛歵ransaction_id> out_trade_no鐨勫 + * @return 鍊 + **/ + public function GetOut_trade_no() + { + return $this->values['out_trade_no']; + } + /** + * 鍒ゆ柇鍟嗘埛绯荤粺鍐呴儴鐨勮鍗曞彿,transaction_id銆乷ut_trade_no浜岄変竴锛屽鏋滃悓鏃跺瓨鍦ㄤ紭鍏堢骇锛歵ransaction_id> out_trade_no鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsOut_trade_noSet() + { + return array_key_exists('out_trade_no', $this->values); + } + + + /** + * 璁剧疆闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶 + * @param string $value + **/ + public function SetNonce_str($value) + { + $this->values['nonce_str'] = $value; + } + /** + * 鑾峰彇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鐨勫 + * @return 鍊 + **/ + public function GetNonce_str() + { + return $this->values['nonce_str']; + } + /** + * 鍒ゆ柇闅忔満瀛楃涓诧紝涓嶉暱浜32浣嶃傛帹鑽愰殢鏈烘暟鐢熸垚绠楁硶鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsNonce_strSet() + { + return array_key_exists('nonce_str', $this->values); + } +} + +/** + * + * 鎻愪氦JSAPI杈撳叆瀵硅薄 + * @author widyhu + * + */ +class WxPayJsApiPay extends WxPayDataBase +{ + /** + * 璁剧疆寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D + * @param string $value + **/ + public function SetAppid($value) + { + $this->values['appId'] = $value; + } + /** + * 鑾峰彇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鐨勫 + * @return 鍊 + **/ + public function GetAppid() + { + return $this->values['appId']; + } + /** + * 鍒ゆ柇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsAppidSet() + { + return array_key_exists('appId', $this->values); + } + + + /** + * 璁剧疆鏀粯鏃堕棿鎴 + * @param string $value + **/ + public function SetTimeStamp($value) + { + $this->values['timeStamp'] = $value; + } + /** + * 鑾峰彇鏀粯鏃堕棿鎴崇殑鍊 + * @return 鍊 + **/ + public function GetTimeStamp() + { + return $this->values['timeStamp']; + } + /** + * 鍒ゆ柇鏀粯鏃堕棿鎴虫槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsTimeStampSet() + { + return array_key_exists('timeStamp', $this->values); + } + + /** + * 闅忔満瀛楃涓 + * @param string $value + **/ + public function SetNonceStr($value) + { + $this->values['nonceStr'] = $value; + } + /** + * 鑾峰彇notify闅忔満瀛楃涓插 + * @return 鍊 + **/ + public function GetReturn_code() + { + return $this->values['nonceStr']; + } + /** + * 鍒ゆ柇闅忔満瀛楃涓叉槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsReturn_codeSet() + { + return array_key_exists('nonceStr', $this->values); + } + + + /** + * 璁剧疆璁㈠崟璇︽儏鎵╁睍瀛楃涓 + * @param string $value + **/ + public function SetPackage($value) + { + $this->values['package'] = $value; + } + /** + * 鑾峰彇璁㈠崟璇︽儏鎵╁睍瀛楃涓茬殑鍊 + * @return 鍊 + **/ + public function GetPackage() + { + return $this->values['package']; + } + /** + * 鍒ゆ柇璁㈠崟璇︽儏鎵╁睍瀛楃涓叉槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsPackageSet() + { + return array_key_exists('package', $this->values); + } + + /** + * 璁剧疆绛惧悕鏂瑰紡 + * @param string $value + **/ + public function SetSignType($value) + { + $this->values['signType'] = $value; + } + /** + * 鑾峰彇绛惧悕鏂瑰紡 + * @return 鍊 + **/ + public function GetSignType() + { + return $this->values['signType']; + } + /** + * 鍒ゆ柇绛惧悕鏂瑰紡鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsSignTypeSet() + { + return array_key_exists('signType', $this->values); + } + + /** + * 璁剧疆绛惧悕鏂瑰紡 + * @param string $value + **/ + public function SetPaySign($value) + { + $this->values['paySign'] = $value; + } + /** + * 鑾峰彇绛惧悕鏂瑰紡 + * @return 鍊 + **/ + public function GetPaySign() + { + return $this->values['paySign']; + } + /** + * 鍒ゆ柇绛惧悕鏂瑰紡鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsPaySignSet() + { + return array_key_exists('paySign', $this->values); + } +} + +/** + * + * 鎵爜鏀粯妯″紡涓鐢熸垚浜岀淮鐮佸弬鏁 + * @author widyhu + * + */ +class WxPayBizPayUrl extends WxPayDataBaseSignMd5 +{ + /** + * 璁剧疆寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D + * @param string $value + **/ + public function SetAppid($value) + { + $this->values['appid'] = $value; + } + /** + * 鑾峰彇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鐨勫 + * @return 鍊 + **/ + public function GetAppid() + { + return $this->values['appid']; + } + /** + * 鍒ゆ柇寰俊鍒嗛厤鐨勫叕浼楄处鍙稩D鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsAppidSet() + { + return array_key_exists('appid', $this->values); + } + + + /** + * 璁剧疆寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿 + * @param string $value + **/ + public function SetMch_id($value) + { + $this->values['mch_id'] = $value; + } + /** + * 鑾峰彇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鐨勫 + * @return 鍊 + **/ + public function GetMch_id() + { + return $this->values['mch_id']; + } + /** + * 鍒ゆ柇寰俊鏀粯鍒嗛厤鐨勫晢鎴峰彿鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsMch_idSet() + { + return array_key_exists('mch_id', $this->values); + } + + /** + * 璁剧疆鏀粯鏃堕棿鎴 + * @param string $value + **/ + public function SetTime_stamp($value) + { + $this->values['time_stamp'] = $value; + } + /** + * 鑾峰彇鏀粯鏃堕棿鎴崇殑鍊 + * @return 鍊 + **/ + public function GetTime_stamp() + { + return $this->values['time_stamp']; + } + /** + * 鍒ゆ柇鏀粯鏃堕棿鎴虫槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsTime_stampSet() + { + return array_key_exists('time_stamp', $this->values); + } + + /** + * 璁剧疆闅忔満瀛楃涓 + * @param string $value + **/ + public function SetNonce_str($value) + { + $this->values['nonce_str'] = $value; + } + /** + * 鑾峰彇闅忔満瀛楃涓茬殑鍊 + * @return 鍊 + **/ + public function GetNonce_str() + { + return $this->values['nonce_str']; + } + /** + * 鍒ゆ柇闅忔満瀛楃涓叉槸鍚﹀瓨鍦 + * @return true 鎴 false + **/ + public function IsNonce_strSet() + { + return array_key_exists('nonce_str', $this->values); + } + + /** + * 璁剧疆鍟嗗搧ID + * @param string $value + **/ + public function SetProduct_id($value) + { + $this->values['product_id'] = $value; + } + /** + * 鑾峰彇鍟嗗搧ID鐨勫 + * @return 鍊 + **/ + public function GetProduct_id() + { + return $this->values['product_id']; + } + /** + * 鍒ゆ柇鍟嗗搧ID鏄惁瀛樺湪 + * @return true 鎴 false + **/ + public function IsProduct_idSet() + { + return array_key_exists('product_id', $this->values); + } +} + diff --git a/public/php_sdk_v3.0.10/lib/WxPay.Exception.php b/public/php_sdk_v3.0.10/lib/WxPay.Exception.php new file mode 100755 index 0000000000000000000000000000000000000000..98c91e5061ac45dfc138a737f103eb8e28bb83c2 --- /dev/null +++ b/public/php_sdk_v3.0.10/lib/WxPay.Exception.php @@ -0,0 +1,13 @@ +getMessage(); + } +} diff --git a/public/php_sdk_v3.0.10/lib/WxPay.Notify.php b/public/php_sdk_v3.0.10/lib/WxPay.Notify.php new file mode 100755 index 0000000000000000000000000000000000000000..3ce91d6479286a3ed082977f256f67373634211a --- /dev/null +++ b/public/php_sdk_v3.0.10/lib/WxPay.Notify.php @@ -0,0 +1,105 @@ +config = $config; + $msg = "OK"; + //褰撹繑鍥瀎alse鐨勬椂鍊欙紝琛ㄧずnotify涓皟鐢∟otifyCallBack鍥炶皟澶辫触鑾峰彇绛惧悕鏍¢獙澶辫触锛屾鏃剁洿鎺ュ洖澶嶅け璐 + $result = WxpayApi::notify($config, array($this, 'NotifyCallBack'), $msg); + if($result == false){ + $this->SetReturn_code("FAIL"); + $this->SetReturn_msg($msg); + $this->ReplyNotify(false); + return; + } else { + //璇ュ垎鏀湪鎴愬姛鍥炶皟鍒癗otifyCallBack鏂规硶锛屽鐞嗗畬鎴愪箣鍚庢祦绋 + $this->SetReturn_code("SUCCESS"); + $this->SetReturn_msg("OK"); + } + $this->ReplyNotify($needSign); + } + + /** + * + * 鍥炶皟鏂规硶鍏ュ彛锛屽瓙绫诲彲閲嶅啓璇ユ柟娉 + //TODO 1銆佽繘琛屽弬鏁版牎楠 + //TODO 2銆佽繘琛岀鍚嶉獙璇 + //TODO 3銆佸鐞嗕笟鍔¢昏緫 + * 娉ㄦ剰锛 + * 1銆佸井淇″洖璋冭秴鏃舵椂闂翠负2s锛屽缓璁敤鎴蜂娇鐢ㄥ紓姝ュ鐞嗘祦绋嬶紝纭鎴愬姛涔嬪悗绔嬪埢鍥炲寰俊鏈嶅姟鍣 + * 2銆佸井淇℃湇鍔″櫒鍦ㄨ皟鐢ㄥけ璐ユ垨鑰呮帴鍒板洖鍖呬负闈炵‘璁ゅ寘鐨勬椂鍊欙紝浼氬彂璧烽噸璇曪紝闇纭繚浣犵殑鍥炶皟鏄彲浠ラ噸鍏 + * @param WxPayNotifyResults $objData 鍥炶皟瑙i噴鍑虹殑鍙傛暟 + * @param WxPayConfigInterface $config + * @param string $msg 濡傛灉鍥炶皟澶勭悊澶辫触锛屽彲浠ュ皢閿欒淇℃伅杈撳嚭鍒拌鏂规硶 + * @return true鍥炶皟鍑烘潵瀹屾垚涓嶉渶瑕佺户缁洖璋冿紝false鍥炶皟澶勭悊鏈畬鎴愰渶瑕佺户缁洖璋 + */ + public function NotifyProcess($objData, $config, &$msg) + { + //TODO 鐢ㄦ埛鍩虹璇ョ被涔嬪悗闇瑕侀噸鍐欒鏂规硶锛屾垚鍔熺殑鏃跺欒繑鍥瀟rue锛屽け璐ヨ繑鍥瀎alse + return false; + } + + /** + * + * 涓氬姟鍙互缁ф壙璇ユ柟娉曪紝鎵撳嵃XML鏂逛究瀹氫綅. + * @param string $xmlData 杩斿洖鐨剎ml鍙傛暟 + * + **/ + public function LogAfterProcess($xmlData) + { + return; + } + + /** + * + * notify鍥炶皟鏂规硶锛岃鏂规硶涓渶瑕佽祴鍊奸渶瑕佽緭鍑虹殑鍙傛暟,涓嶅彲閲嶅啓 + * @param array $data + * @return true鍥炶皟鍑烘潵瀹屾垚涓嶉渶瑕佺户缁洖璋冿紝false鍥炶皟澶勭悊鏈畬鎴愰渶瑕佺户缁洖璋 + */ + final public function NotifyCallBack($data) + { + $msg = "OK"; + $result = $this->NotifyProcess($data, $this->config, $msg); + + if($result == true){ + $this->SetReturn_code("SUCCESS"); + $this->SetReturn_msg("OK"); + } else { + $this->SetReturn_code("FAIL"); + $this->SetReturn_msg($msg); + } + return $result; + } + + /** + * + * 鍥炲閫氱煡 + * @param bool $needSign 鏄惁闇瑕佺鍚嶈緭鍑 + */ + final private function ReplyNotify($needSign = true) + { + //濡傛灉闇瑕佺鍚 + if($needSign == true && + $this->GetReturn_code() == "SUCCESS") + { + $this->SetSign($this->config); + } + + $xml = $this->ToXml(); + $this->LogAfterProcess($xml); + WxpayApi::replyNotify($xml); + } +} \ No newline at end of file