wemall-mobile is an Android app mall based on WeMall. You only need to upload the interface file in the original mall directory to complete the server-side configuration. The client can be customized and modified. This article shares the Alipay interface public functions of the wemall app mall source code Android. This class is the core processing file of the public functions called by the request and notification return files for technicians to refer to and learn.
The following code is only a sample code provided to facilitate merchant testing. Merchants can write it according to the technical documentation according to the needs of their own websites. It is not necessary to use this code. This code is only for learning and researching the Alipay interface and is only provided as a reference.
Concatenate all the elements of the array into a string using the "&" character according to the pattern of "parameter = parameter value"
<?php<br />
<br />
function createLinkstring($para) {<br />
$arg = "";<br />
While (list ($key, $val) = each ($para)) {<br />
$arg.=$key."=".$val."&";<br />
}<br />
//Remove the last & character <br />
$arg = substr($arg,0,count($arg)-2);<br />
<br />
//If there is an escape character, remove the escape <br />
If(get_magic_quotes_gpc()){$arg = stripslashes($arg);}<br />
<br />
Return $arg;<br />
}<br />
/**<br />
* Concatenate all the elements of the array into a string using the "&" character according to the pattern of "parameter = parameter value", and perform urlencode encoding on the string<br />
* @param $para Array to be spliced<br />
* return the string after the splicing is completed<br />
*/<br />
function createLinkstringUrlencode($para) {<br />
$arg = "";<br />
While (list ($key, $val) = each ($para)) {<br />
$arg.=$key."=".urlencode($val)."&";<br />
}<br />
//Remove the last & character <br />
$arg = substr($arg,0,count($arg)-2);<br />
<br />
//If there is an escape character, remove the escape <br />
If(get_magic_quotes_gpc()){$arg = stripslashes($arg);}<br />
<br />
Return $arg;<br />
}<br />
/**<br />
* Remove null values and signature parameters in the array<br />
* @param $para Signature parameter group<br />
* return The new signature parameter group after removing the null value and signature parameters<br />
*/<br />
function paraFilter($para) {<br />
$para_filter = array();<br />
While (list ($key, $val) = each ($para)) {<br />
If($key == "sign" || $key == "sign_type" || $val == "")continue;<br />
Else $ Para_filter [$ key] = $ Para [$ key]; <br />
}<br />
Return $para_filter;<br />
}<br />
/**<br />
* Sort the array<br />
* @param $para Array before sorting<br />
* return sorted array<br />
*/<br />
function argSort($para) {<br />
ksort($para);<br />
reset($para);<br />
Return $para;<br />
}<br />
/**<br />
* Write logs to facilitate testing (depending on the website requirements, you can also change the records to be stored in the database) <br />
* Note: The server needs to enable fopen configuration<br />
* @param $word The text content to be written in the log Default value: null<br />
*/<br />
function logResult($word='') {<br />
$fp = fopen("log.txt","a");<br />
flock($fp, LOCK_EX) ;<br />
fwrite($fp,"Execution date:".strftime("%Y%m%d%H%M%S",time())."n".$word."n");<br />
flock($fp, LOCK_UN);<br />
fclose($fp);<br />
}<br />
<br />
/**<br />
* Remotely obtain data, POST mode<br />
* Note: <br />
* 1. To use Crul, you need to modify the settings of the php.ini file in the server. Find php_curl.dll and remove the ";" in front of it<br />
* 2. cacert.pem in the folder is an SSL certificate. Please ensure that its path is valid. The current default path is: getcwd().'\cacert.pem'<br />
* @param $url specifies the full path address of the URL<br />
* @param $cacert_url specifies the absolute path of the current working directory<br />
* @param $para Requested data<br />
* @param $input_charset encoding format. Default value: null <br />* return remote output data<br />
*/<br />
function getHttpResponsePOST($url, $cacert_url, $para, $input_charset = '') {<br />
<br />
If (trim($input_charset) != '') {<br />
$url = $url."_input_charset=".$input_charset;<br />
}<br />
$curl = curl_init($url);<br />
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//SSL certificate authentication<br />
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//Strict authentication<br />
curl_setopt($curl, CURLOPT_CAINFO,$cacert_url);//Certificate address<br />
curl_setopt($curl, CURLOPT_HEADER, 0); // Filter HTTP header<br />
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1); // Display the output results <br />
curl_setopt($curl,CURLOPT_POST,true); // post transfer data<br />
curl_setopt($curl,CURLOPT_POSTFIELDS,$para); // post transfer data<br />
$responseText = curl_exec($curl);<br />
//var_dump( curl_error($curl) );//If an exception occurs during curl execution, you can turn on this switch to view the exception content<br />
curl_close($curl);<br />
<br />
Return $responseText;<br />
}<br />
<br />
/**<br />
* Remotely obtain data, GET mode<br />
* Note: <br />
* 1. To use Crul, you need to modify the settings of the php.ini file in the server. Find php_curl.dll and remove the ";" in front of it<br />
* 2. cacert.pem in the folder is an SSL certificate. Please ensure that its path is valid. The current default path is: getcwd().'\cacert.pem'<br />
* @param $url specifies the full path address of the URL<br />
* @param $cacert_url specifies the absolute path of the current working directory<br />
* return remote output data<br />
*/<br />
function getHttpResponseGET($url,$cacert_url) {<br />
$curl = curl_init($url);<br />
curl_setopt($curl, CURLOPT_HEADER, 0); // Filter HTTP header<br />
curl_setopt($curl,CURLOPT_RETURNTRANSFER, 1); // Display the output results <br />
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, true);//SSL certificate authentication<br />
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);//Strict authentication<br />
curl_setopt($curl, CURLOPT_CAINFO,$cacert_url);//Certificate address<br />
$responseText = curl_exec($curl);<br />
//var_dump( curl_error($curl) );//If an exception occurs during curl execution, you can turn on this switch to view the exception content<br />
curl_close($curl);<br />
<br />
Return $responseText;<br />
}<br />
<br />
/**<br />
* Implement multiple character encoding methods<br />
* @param $input The string that needs to be encoded<br />
* @param $_output_charset Output encoding format<br />
* @param $_input_charset Input encoding format<br />
* return the encoded string<br />
*/<br />
function charsetEncode($input,$_output_charset,$_input_charset) {<br />
$output = "";<br />
If(!isset($_output_charset) )$_output_charset = $_input_charset;<br />
If($_input_charset == $_output_charset || $input ==null ) {<br />
$output = $input;<br />
} elseif (function_exists("mb_convert_encoding")) {<br />
$output = mb_convert_encoding($input,$_output_charset,$_input_charset);<br />
} elseif(function_exists("iconv")) {<br />
$output = iconv($_input_charset,$_output_charset,$input);<br />
else die("sorry, you have no libs support for charset change.");<br />
Return $output;<br />
}<br />
/**<br />
* Implement multiple character decoding methods<br />
* @param $input The string to be decoded<br />
* @param $_output_charset Output decoding format<br /> * @param $_input_charset 输入的解码格式<br />
* return 解码后的字符串<br />
*/<br />
function charsetDecode($input,$_input_charset ,$_output_charset) {<br />
$output = "";<br />
if(!isset($_input_charset) )$_input_charset = $_input_charset ;<br />
if($_input_charset == $_output_charset || $input ==null ) {<br />
$output = $input;<br />
} elseif (function_exists("mb_convert_encoding")) {<br />
$output = mb_convert_encoding($input,$_output_charset,$_input_charset);<br />
} elseif(function_exists("iconv")) {<br />
$output = iconv($_input_charset,$_output_charset,$input);<br />
} else die("sorry, you have no libs support for charset changes.");<br />
return $output;<br />
}<br />
?>
wemall官网地址:http://www.wemallshop.com