php 위 챗 공중 번호 기업 이체 기능 실현

기업 지불 은 상인 이 직접 사용자 에 게 위 챗 잔돈 을 지불 하 는 능력 을 제공 하고 플랫폼 조작 과 인터페이스 호출 두 가지 방식 을 지원 하 며 자금 이 장부 에 도착 하 는 속도 가 빠 르 고 사용 과 조회 가 편리 하 다.주로 합 리 적 인 상인 이 사용자 에 대한 지불 수 요 를 해결 하 는 데 쓰 인 다.예 를 들 어 보험 배상 청구,복권 교환 등 이다.
특징.
  • 시작 방식 이 유연 하고 페이지 나 인 터 페 이 스 를 통 해 시작 할 수 있 습 니 다
  • 위 챗 메시지 가 전달 되 었 고 사용 자 는 신속하게 입금 상세 한 상황 을 알 게 되 었 습 니 다
  • 실명 검 사 를 지원 하고 수취인 의 정 체 를 판단 합 니 다
  • openid 를 통 해 지불 을 실현 할 수 있 고 사용자 의 민감 한 프라이버시 정보 가 필요 하지 않 습 니 다
  • 4.567917.입금 속도 가 빠 르 고 시작 한 후에 사용 자 는 몇 분 안에 지불 을 받 을 수 있 습 니 다기업 이 체 는 위 챗 상점 플랫폼 으로 이 체 를 해 야 합 니 다=제품 센터=기업 이 잔돈 을 지불 하고 이 기능 을 켜 야 합 니 다.

    다음은 프로그램 캡 처:
    첫 번 째 단계:설정 매개 변수 설정
    
    $url='https://api.mch.weixin.qq.com/mmpaymkttransfers/promotion/transfers';
    $pars = array();
    $pars['mch_appid'] =$this->module['config']['appid'];
    $pars['mchid']=$this->module['config']['mchid'];
    $pars['nonce_str'] =random(32);
    $pars['partner_trade_no'] =time().random(3,1);
    $pars['openid'] =$openid;
    $pars['check_name'] ='NO_CHECK' ;
    //$pars['re_user_name'] ='' ;
    $monet_finall = $price * 100;
    $pars['amount'] =$monet_finall; //      1%    *100
    $pars['desc'] ='       '.$price.'   ';
    $pars['spbill_create_ip'] =$this->module['config']['ip'];
    
    ksort($pars, SORT_STRING);
    $string1 = '';
    foreach ($pars as $k => $v) {
      $string1 .= "{$k}={$v}&";
    }
    
    $string1 .= "key=".$this->module['config']['password'];
    $pars['sign'] = strtoupper(md5($string1));
    $xml = array2xml($pars);
    $extras = array();
    $extras['CURLOPT_CAINFO'] = ATTACHMENT_ROOT . '/withdraw/cert/rootca.pem.' . $_W['uniacid'];
    $extras['CURLOPT_SSLCERT'] = ATTACHMENT_ROOT   . '/withdraw/cert/apiclient_cert.pem.' . $_W['uniacid'];
    $extras['CURLOPT_SSLKEY'] = ATTACHMENT_ROOT . '/withdraw/cert/apiclient_key.pem.' . $_W['uniacid'];
    $procResult = null;
    STEP 2:CURL 위 챗 서버 요청
    
    load()->func('communication');
    $resp = ihttp_request($url, $xml, $extras);
    그 중 ihttprequest 함수 내용 은:
    
    function ihttp_request($url, $post = '', $extra = array(), $timeout = 60) {
      $urlset = parse_url($url);
      if (empty($urlset['path'])) {
       $urlset['path'] = '/';
      }
      if (!empty($urlset['query'])) {
       $urlset['query'] = "?{$urlset['query']}";
      }
      if (empty($urlset['port'])) {
         }
      if (strexists($url, 'https://') && !extension_loaded('openssl')) {
       if (!extension_loaded("openssl")) {
         message('    PHP   openssl');
       }
      }
      if (function_exists('curl_init') && function_exists('curl_exec')) {
       $ch = curl_init();
       if (!empty($extra['ip'])) {
         $extra['Host'] = $urlset['host'];
         $urlset['host'] = $extra['ip'];
         unset($extra['ip']);
       }
       curl_setopt($ch, CURLOPT_URL, $urlset['scheme'] . '://' . $urlset['host'] . ($urlset['port'] == '80' || empty($urlset['port']) ? '' : ':' . $urlset['port']) . $urlset['path'] . $urlset['query']);
       curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
       @curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
       curl_setopt($ch, CURLOPT_HEADER, 1);
       @curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_0);
       if ($post) {
         if (is_array($post)) {
          $filepost = false;
                foreach ($post as $name => &$value) {
            if (version_compare(phpversion(), '5.6') >= 0 && substr($value, 0, 1) == '@') {
             $value = new CURLFile(ltrim($value, '@'));
            }
            if ((is_string($value) && substr($value, 0, 1) == '@') || (class_exists('CURLFile') && $value instanceof CURLFile)) {
             $filepost = true;
            }
          }
          if (!$filepost) {
            $post = http_build_query($post);
          }
         }
         curl_setopt($ch, CURLOPT_POST, 1);
         curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
       }
       if (!empty($GLOBALS['_W']['config']['setting']['proxy'])) {
         $urls = parse_url($GLOBALS['_W']['config']['setting']['proxy']['host']);
         if (!empty($urls['host'])) {
          curl_setopt($ch, CURLOPT_PROXY, "{$urls['host']}:{$urls['port']}");
          $proxytype = 'CURLPROXY_' . strtoupper($urls['scheme']);
          if (!empty($urls['scheme']) && defined($proxytype)) {
            curl_setopt($ch, CURLOPT_PROXYTYPE, constant($proxytype));
          } else {
            curl_setopt($ch, CURLOPT_PROXYTYPE, CURLPROXY_HTTP);
            curl_setopt($ch, CURLOPT_HTTPPROXYTUNNEL, 1);
          }
          if (!empty($GLOBALS['_W']['config']['setting']['proxy']['auth'])) {
            curl_setopt($ch, CURLOPT_PROXYUSERPWD, $GLOBALS['_W']['config']['setting']['proxy']['auth']);
          }
         }
       }
       curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
       curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
       curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
       curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
       curl_setopt($ch, CURLOPT_SSLVERSION, 1);
       if (defined('CURL_SSLVERSION_TLSv1')) {
         curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1);
       }
       curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1; WOW64; rv:9.0.1) Gecko/20100101 Firefox/9.0.1');
       if (!empty($extra) && is_array($extra)) {
         $headers = array();
         foreach ($extra as $opt => $value) {
          if (strexists($opt, 'CURLOPT_')) {
            curl_setopt($ch, constant($opt), $value);
          } elseif (is_numeric($opt)) {
            curl_setopt($ch, $opt, $value);
          } else {
            $headers[] = "{$opt}: {$value}";
          }
         }
         if (!empty($headers)) {
          curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
         }
       }
       $data = curl_exec($ch);
       $status = curl_getinfo($ch);
       $errno = curl_errno($ch);
       $error = curl_error($ch);
       curl_close($ch);
       if ($errno || empty($data)) {
         return error(1, $error);
       } else {
         return ihttp_response_parse($data);
       }
      }
      $method = empty($post) ? 'GET' : 'POST';
      $fdata = "{$method} {$urlset['path']}{$urlset['query']} HTTP/1.1\r
    "; $fdata .= "Host: {$urlset['host']}\r
    "; if (function_exists('gzdecode')) { $fdata .= "Accept-Encoding: gzip, deflate\r
    "; } $fdata .= "Connection: close\r
    "; if (!empty($extra) && is_array($extra)) { foreach ($extra as $opt => $value) { if (!strexists($opt, 'CURLOPT_')) { $fdata .= "{$opt}: {$value}\r
    "; } } } $body = ''; if ($post) { if (is_array($post)) { $body = http_build_query($post); } else { $body = urlencode($post); } $fdata .= 'Content-Length: ' . strlen($body) . "\r
    \r
    {$body}"; } else { $fdata .= "\r
    "; } if ($urlset['scheme'] == 'https') { $fp = fsockopen('ssl://' . $urlset['host'], $urlset['port'], $errno, $error); } else { $fp = fsockopen($urlset['host'], $urlset['port'], $errno, $error); } stream_set_blocking($fp, true); stream_set_timeout($fp, $timeout); if (!$fp) { return error(1, $error); } else { fwrite($fp, $fdata); $content = ''; while (!feof($fp)) $content .= fgets($fp, 512); fclose($fp); return ihttp_response_parse($content, true); } }
    세 번 째 단계:위 챗 서버 의 반환 값 을 분석 하고 되 돌려 줍 니 다.
    
    if (is_error($resp)) {
      $procResult = $resp;
    } else {
      $arr=json_decode(json_encode((array) simplexml_load_string($resp['content'])), true);
      $xml = '<?xml version="1.0" encoding="utf-8"?>' . $resp['content'];
      $dom = new \DOMDocument();
      if ($dom->loadXML($xml)) {
        $xpath = new \DOMXPath($dom);
        $code = $xpath->evaluate('string(//xml/return_code)');
        $ret = $xpath->evaluate('string(//xml/result_code)');
        if (strtolower($code) == 'success' && strtolower($ret) == 'success') {
          $procResult = array('errno'=>0,'error'=>'success');;
        } else {
          $error = $xpath->evaluate('string(//xml/err_code_des)');
          $procResult = array('errno'=>-2,'error'=>$error);
        }
      } else {
        $procResult = array('errno'=>-1,'error'=>'    ');
      }
    }
    
    return $procResult;
    
    이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.

    좋은 웹페이지 즐겨찾기