欧美成人午夜免费全部完,亚洲午夜福利精品久久,а√最新版在线天堂,另类亚洲综合区图片小说区,亚洲欧美日韩精品色xxx

扣丁學(xué)堂PHP培訓(xùn)簡(jiǎn)述PHP如何實(shí)現(xiàn)微信公眾號(hào)企業(yè)轉(zhuǎn)賬功能

2019-08-06 16:03:29 4206瀏覽

如今大家很少使用現(xiàn)金支付了,出門(mén)帶一部手機(jī)就能解決個(gè)人消費(fèi)問(wèn)題,本篇文章扣丁學(xué)堂PHP培訓(xùn)小編給讀者們分享一下PHP如何實(shí)現(xiàn)微信公眾號(hào)企業(yè)轉(zhuǎn)賬功能,感興趣的小伙伴就隨小編來(lái)了解一下吧。


扣丁學(xué)堂PHP培訓(xùn)簡(jiǎn)述PHP如何實(shí)現(xiàn)微信公眾號(hào)企業(yè)轉(zhuǎn)賬功能


企業(yè)付款提供由商戶直接付錢(qián)至用戶微信零錢(qián)的能力,支持平臺(tái)操作及接口調(diào)用兩種方式,資金到賬速度快,使用及查詢方便。主要用來(lái)解決合理的商戶對(duì)用戶付款需求,比如:保險(xiǎn)理賠、彩票兌換等等。


點(diǎn):


發(fā)起方式靈活,可通過(guò)頁(yè)面或接口發(fā)起

微信消息觸達(dá),用戶及時(shí)獲知入賬詳情

支持實(shí)名校驗(yàn),判斷收款人真實(shí)身份

通過(guò)openid即可實(shí)現(xiàn)付款,無(wú)需用戶敏感隱私信息

到賬速度快,在發(fā)起后,用戶可在幾分鐘內(nèi)收到付款


企業(yè)轉(zhuǎn)賬需要到微信商戶平臺(tái)=》產(chǎn)品中心=》企業(yè)付款到零錢(qián),開(kāi)啟此功能


扣丁學(xué)堂PHP視頻教程


第一步:設(shè)置配置參數(shù)


$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'] ='您已成功提現(xiàn) '.$price.' 現(xiàn)金';
$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;


第二步:CURL請(qǐng)求微信服務(wù)器


load()->func('communication');
$resp = ihttp_request($url, $xml, $extras);


其中ihttp_request函數(shù)內(nèi)容是:


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('請(qǐng)開(kāi)啟您PHP環(huán)境的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\n";
  $fdata .= "Host: {$urlset['host']}\r\n";
  if (function_exists('gzdecode')) {
   $fdata .= "Accept-Encoding: gzip, deflate\r\n";
  }
  $fdata .= "Connection: close\r\n";
  if (!empty($extra) && is_array($extra)) {
   foreach ($extra as $opt => $value) {
     if (!strexists($opt, 'CURLOPT_')) {
      $fdata .= "{$opt}: {$value}\r\n";
     }
   }
  }
  $body = '';
  if ($post) {
   if (is_array($post)) {
     $body = http_build_query($post);
   } else {
     $body = urlencode($post);
   }
   $fdata .= 'Content-Length: ' . strlen($body) . "\r\n\r\n{$body}";
  } else {
   $fdata .= "\r\n";
  }
  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);
  }
}


第三步:解析分析微信服務(wù)器返回值并返回。


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'=>'未知錯(cuò)誤');
  }
}

return $procResult;

想要了解更多關(guān)于PHP開(kāi)發(fā)方面內(nèi)容的小伙伴,請(qǐng)關(guān)注扣丁學(xué)堂PHP培訓(xùn)官網(wǎng)、微信等平臺(tái),扣丁學(xué)堂IT職業(yè)在線學(xué)習(xí)教育有專(zhuān)業(yè)的PHP講師為您指導(dǎo),此外扣丁學(xué)堂老師精心推出的PHP視頻教程定能讓你快速掌握PHP從入門(mén)到精通開(kāi)發(fā)實(shí)戰(zhàn)技能??鄱W(xué)堂PHP技術(shù)交流群:374332265。


扣丁學(xué)堂微信公眾號(hào)                          Python全棧開(kāi)發(fā)爬蟲(chóng)人工智能機(jī)器學(xué)習(xí)數(shù)據(jù)分析免費(fèi)公開(kāi)課直播間


      【關(guān)注微信公眾號(hào)獲取更多學(xué)習(xí)資料】         【掃碼進(jìn)入Python全棧開(kāi)發(fā)免費(fèi)公開(kāi)課】



查看更多關(guān)于“php培訓(xùn)資訊”的相關(guān)文章>>

標(biāo)簽: PHP培訓(xùn) PHP視頻教程 PHP在線視頻 PHP學(xué)習(xí)視頻 Laravel框架

熱門(mén)專(zhuān)區(qū)

暫無(wú)熱門(mén)資訊

課程推薦

微信
微博
15311698296

全國(guó)免費(fèi)咨詢熱線

郵箱:codingke@1000phone.com

官方群:148715490

北京千鋒互聯(lián)科技有限公司版權(quán)所有   北京市海淀區(qū)寶盛北里西區(qū)28號(hào)中關(guān)村智誠(chéng)科創(chuàng)大廈4層
京ICP備2021002079號(hào)-2   Copyright ? 2017 - 2022
返回頂部 返回頂部