Пример #1
0
 /**
  *
  * 构造获取open和access_toke的url地址
  * @param string $code,微信跳转带回的code
  *
  * @return 请求的url
  */
 private function __CreateOauthUrlForOpenid($code)
 {
     $urlObj['appid'] = Wxpay::getConfig('appid');
     $urlObj['secret'] = Wxpay::getConfig('appsecret');
     $urlObj['code'] = $code;
     $urlObj['grant_type'] = 'authorization_code';
     $bizString = $this->toUrlParams($urlObj);
     return 'https://api.weixin.qq.com/sns/oauth2/access_token?' . $bizString;
 }
Пример #2
0
 /**
  * 以post方式提交xml到对应的接口url
  *
  * @param string $xml  需要post的xml数据
  * @param string $url  url
  * @param bool $useCert 是否需要证书,默认不需要
  * @param int $second   url执行超时时间,默认30s
  * @throws WxPayException
  */
 private function postXmlCurl($xml, $url, $useCert = false, $second = 30)
 {
     $ch = curl_init();
     //设置超时
     curl_setopt($ch, CURLOPT_TIMEOUT, $second);
     //如果有配置代理这里就设置代理
     if (Wxpay::getConfig('curl_proxy_host') != '0.0.0.0' && Wxpay::getConfig('curl_proxy_port') != 0) {
         curl_setopt($ch, CURLOPT_PROXY, Wxpay::getConfig('curl_proxy_host'));
         curl_setopt($ch, CURLOPT_PROXYPORT, Wxpay::getConfig('curl_proxy_port'));
     }
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, TRUE);
     curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
     //严格校验
     //设置header
     curl_setopt($ch, CURLOPT_HEADER, FALSE);
     //要求结果为字符串且输出到屏幕上
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     if ($useCert == true) {
         //设置证书
         //使用证书:cert 与 key 分别属于两个.pem文件
         curl_setopt($ch, CURLOPT_SSLCERTTYPE, 'PEM');
         curl_setopt($ch, CURLOPT_SSLCERT, Wxpay::getConfig('sslcert_path'));
         curl_setopt($ch, CURLOPT_SSLKEYTYPE, 'PEM');
         curl_setopt($ch, CURLOPT_SSLKEY, Wxpay::getConfig('sslkey_path'));
     }
     //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);
     }
 }
Пример #3
0
 /**
  * 生成签名
  * @return 签名,本函数不覆盖sign成员变量,如要设置签名需要调用setSign方法赋值
  */
 public function makeSign()
 {
     //签名步骤一:按字典序排序参数
     ksort($this->values);
     $string = $this->toUrlParams();
     //签名步骤二:在string后加入KEY
     $string = $string . '&key=' . Wxpay::getConfig('key');
     //签名步骤三:MD5加密
     $string = md5($string);
     //签名步骤四:所有字符转为大写
     $result = strtoupper($string);
     return $result;
 }