$value) { if ($Property = $Reflect->GetProperty($key)) { if ($Property->IsPublic()) $Property->SetValue($this, $value); elseif ($Property->IsPrivate()) throw new Exception('can not access private property: ' . $class_name . '::' . $key . ' in ' . __FILE__ . ' on line ' . __LINE__); elseif ($Property->IsProtected()) throw new Exception('can not access protected property: ' . $class_name . '::' . $key . ' in ' . __FILE__ . ' on line ' . __LINE__); else throw new Exception('can not access unknown property: ' . $class_name . '::' . $key . ' in ' . __FILE__ . ' on line ' . __LINE__); $Property = null; } else throw new Exception('undefined property: ' . $class_name . '::' . $key . ' in ' . __FILE__ . ' on line ' . __LINE__); } } function AlipaySubmit($config) { $this->__construct($config); } /** * 生成签名结果 * @param array $para_sort 已排序要签名的数组 * @return string 签名结果字符串 */ function buildRequestMysign($para_sort) { /// 把数组所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串 $prestr = createLinkstring($para_sort); switch (strtoupper(trim($this->sign_type))) { case 'RSA': $mysign = rsaSign($prestr, $this->rsa_private_key_path); break; case 'MD5': $mysign = md5Sign($prestr, $this->md5_key); break; default : $mysign = ''; } return $mysign; } /** * 生成要请求给支付宝的参数数组 * @param array $para_temp 请求前的参数数组 * @return array 要请求的参数数组 */ function buildRequestPara($para_temp) { //除去待签名参数数组中的空值和签名参数 $para_filter = paraFilter($para_temp); //对待签名参数数组排序 $para_sort = argSort($para_filter); //生成签名结果 $mysign = $this->buildRequestMysign($para_sort); //签名结果与签名方式加入请求提交参数组中 $para_sort['sign'] = $mysign; $para_sort['sign_type'] = strtoupper(trim($this->sign_type)); return $para_sort; } /** * 生成要请求给支付宝的参数数组 * @param array $para_temp 请求前的参数数组 * @return 要请求的参数数组字符串 */ function buildRequestParaToString($para_temp) { /// 待请求参数数组 $para = $this->buildRequestPara($para_temp); /// 把参数组中所有元素,按照“参数=参数值”的模式用“&”字符拼接成字符串,并对字符串做urlencode编码 $request_data = createLinkstringUrlencode($para); return $request_data; } /** * 建立请求,以表单HTML形式构造(默认) * @param array $para_temp 请求参数数组 * @param string $method 提交方式。两个值可选:post、get * @param string $button_name 确认按钮显示文字 * @return string 提交表单HTML文本 */ function buildRequestForm($para_temp, $method, $button_name) { /// 待请求参数数组 $para = $this->buildRequestPara($para_temp); $sHtml = "
"; while (list ($key, $val) = each($para)) { $sHtml .= ""; } /// submit按钮控件请不要含有name属性 $sHtml = $sHtml . "
"; $sHtml = $sHtml . ""; return $sHtml; } /** * 建立请求,以模拟远程HTTP的POST请求方式构造并获取支付宝的处理结果 * @param array $para_temp 请求参数数组 * @return string 支付宝处理结果 */ function buildRequestHttp($para_temp) { /// 待请求参数数组字符串 $request_data = $this->buildRequestPara($para_temp); /// 远程获取数据 $sResult = getHttpResponsePOST($this->alipay_gateway_new, $this->cacert_file_path, $request_data, trim(strtolower($this->input_charset))); return $sResult; } /** * 建立请求,以模拟远程HTTP的POST请求方式构造并获取支付宝的处理结果,带文件上传功能 * @param array $para_temp 请求参数数组 * @param string $file_para_name 文件类型的参数名 * @param string $file_name 文件完整绝对路径 * @return string 支付宝返回处理结果 */ function buildRequestHttpInFile($para_temp, $file_para_name, $file_name) { /// 待请求参数数组 $para = $this->buildRequestPara($para_temp); $para[$file_para_name] = "@".$file_name; /// 远程获取数据 $sResult = getHttpResponsePOST($this->alipay_gateway_new, $this->cacert_file_path, $para, trim(strtolower($this->input_charset))); return $sResult; } /** * 用于防钓鱼,调用接口query_timestamp来获取时间戳的处理函数 * 注意:该功能PHP5环境及以上支持,因此必须服务器、本地电脑中装有支持DOMDocument、SSL的PHP配置环境。建议本地调试时使用PHP开发软件 * return 时间戳字符串 */ function query_timestamp() { $url = $this->alipay_gateway_new . "service=query_timestamp&partner=" . trim(strtolower($this->partner)) . "&_input_charset=" . trim(strtolower($this->input_charset)); $doc = new DOMDocument(); $doc->load($url); $itemEncrypt_key = $doc->getElementsByTagName("encrypt_key"); $encrypt_key = $itemEncrypt_key->item(0)->nodeValue; return $encrypt_key; } }