php 위 챗 공중 번호 기업 이체 기능 실현
특징.
다음은 프로그램 캡 처:
첫 번 째 단계:설정 매개 변수 설정
$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;
이상 이 바로 본 고의 모든 내용 입 니 다.여러분 의 학습 에 도움 이 되 고 저 희 를 많이 응원 해 주 셨 으 면 좋 겠 습 니 다.
이 내용에 흥미가 있습니까?
현재 기사가 여러분의 문제를 해결하지 못하는 경우 AI 엔진은 머신러닝 분석(스마트 모델이 방금 만들어져 부정확한 경우가 있을 수 있음)을 통해 가장 유사한 기사를 추천합니다:
Laravel - 변환된 유효성 검사 규칙으로 API 요청 제공동적 콘텐츠를 위해 API를 통해 Laravel CMS에 연결하는 모바일 앱(또는 웹사이트) 구축을 고려하십시오. 이제 앱은 CMS에서 번역된 콘텐츠를 받을 것으로 예상되는 다국어 앱이 될 수 있습니다. 일반적으로 ...
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
CC BY-SA 2.5, CC BY-SA 3.0 및 CC BY-SA 4.0에 따라 라이센스가 부여됩니다.