$data['mchid'] = $mchid;
$data['description'] = $name;//商品描述
$data['out_trade_no'] = $ordernumber;//订单编号
$data['notify_url'] = "你的域名/你的支付目录路径/notify.php";//回调接口 需根据自己的情况修改
$data['amount']['total'] = intval($money * 1);//金额 单位 分
$data['payer']['openid'] = $openid;//用户openID
$data = json_encode($data);
$key = getSign($data,$urlarr['path'],$noncestr,$time);//签名
$token = sprintf('mchid="%s",serial_no="%s",nonce_str="%s",timestamp="%d",signature="%s"',$mchid,$xlid,$noncestr,$time,$key);//头部信息
$header = array(
'Content-Type:'.'application/json; charset=UTF-8',
'Accept:application/json',
'User-Agent:*/*',
'Authorization: WECHATPAY2-SHA256-RSA2048 '.$token
);
$ret = curl_post_https($url,$data,$header);
$ret = ltrim($ret,'{"prepay_id":"');
$ret = rtrim($ret,'}"');
//微信支付(小程序)签名
$str = getWechartSign($appid,$timeStamp,$noncestr,'prepay_id='.$ret);
$arr = array('appid'=>$appid,'timestamp'=>$timeStamp,'package'=>'prepay_id='.$ret,'paySign'=>$str);
exit(json_encode($arr));
}
$set_body = ‘支付测试’;//支付显示内容
$price = ‘1’;//支付金额
$out_trade_no = $data_s[‘out_trade_no’];//订单号
$timeStamp = $data_s[‘timeStamp’];//时间戳
$openid = $data_s[‘openid’];
$noncestr = $data_s[‘nonceStr’];
wechartAddOrder( s e t b o d y , set_body, setbody,out_trade_no, p r i c e , price, price,openid, t i m e S t a m p , timeStamp, timeStamp,noncestr);
//微信支付签名
function getSign( d a t a = a r r a y ( ) , data=array(), data=array(),url, r a n d s t r , randstr, randstr,time){
KaTeX parse error: Undefined control sequence: \n at position 15: str = "POST"."\̲n̲".url.“\n”.KaTeX parse error: Undefined control sequence: \n at position 7: time."\̲n̲".randstr.“\n”.$data.“\n”;
$key = file_get_contents(‘apiclient_key.pem’);//在商户平台下载的秘钥
s t r = g e t S h a 256 W i t h R S A ( str = getSha256WithRSA( str=getSha256WithRSA(str,$key);
return $str;
}
//调起支付的签名
function getWechartSign( a p p i d , appid, appid,timeStamp, n o n c e s t r , noncestr, noncestr,prepay_id){
$str = KaTeX parse error: Undefined control sequence: \n at position 8: appid."\̲n̲".timeStamp.“\n”.KaTeX parse error: Undefined control sequence: \n at position 11: noncestr."\̲n̲".prepay_id.“\n”;
$key = file_get_contents(‘apiclient_key.pem’);
s t r = g e t S h a 256 W i t h R S A ( str = getSha256WithRSA( str=getSha256WithRSA(str,$key);
return $str;
}
function getSha256WithRSA($content, $privateKey){
$binary_signature = “”;
a l g o = " S H A 256 " ; o p e n s s l s i g n ( algo = "SHA256"; openssl_sign( algo="SHA256";opensslsign(content, $binary_signature, $privateKey, $algo);
s i g n = b a s e 6 4 e n c o d e ( sign = base64_encode( sign=base64encode(binary_signature);
return $sign;
}
/* PHP CURL HTTPS POST */
function curl_post_https( u r l , url, url,data,$header){ // 模拟提交数据函数
c u r l = c u r l i n i t ( ) ; / / 启动一个 C U R L 会话 c u r l s e t o p t ( curl = curl_init(); // 启动一个CURL会话 curl_setopt( curl=curlinit();//启动一个CURL会话curlsetopt(curl, CURLOPT_URL, u r