1.微信统一下单,得到prepayid(预支付交易会话ID)
2.用prepayid二次签名
$resignData = array( 'appid' => $order['appid'] , //appid 'partnerid' => $order['mch_id'] , //商户号 'prepayid' => $order['prepay_id'] , //预支付交易会话ID 'noncestr' => \WxPayApi::getNonceStr() , //随机字符串32位 'timestamp' => time() , //事件戳 'package' => 'Sign=WXPay' //package 默认 sign=WXPay);
请注意:
1)上面参数名(key)必须为小写,不然----无止境的-1错误
2)package参数为必填
开始签名
ksort($resignData); //将参数数组按照参数名ASCII码从小到大排序foreach ($resignData as $key => $item) { if (!empty($item)) { //剔除参数值为空的参数 $newArr[] = $key . '=' . $item; // 整合新的参数数组 }}$stringA = implode("&", $newArr); //使用 & 符号连接参数$stringSignTemp = $stringA . "&key=" . $key;//拼接key// key是在商户平台API安全里自己设置的$stringSignTemp = MD5($stringSignTemp); //将字符串进行MD5加密$sign = strtoupper($stringSignTemp); //将所有字符转换为大写
得到参数,返回给前端
$data['appid'] = $resignData['appid'];$data['partnerid'] = $resignData['partnerid'];$data['prepayid'] = $resignData['prepayid'];$data['package'] = $resignData['package'];$data['noncestr'] = $resignData['noncestr'];$data['timestamp'] = time();$data['sign'] = $sign;