如何将PHP小程序支付代码改写为长尾关键词?
- 内容介绍
- 文章标签
- 相关推荐
本文共计533个文字,预计阅读时间需要3分钟。
小程序端页面初始化内容如下:javascriptPage({ data: { userN: '' }, payInput: function(e) { console.log(e); this.setData({ userN: e.detail.value }); }, loginBtnClick: function() { getApp().onLaunch(function(openid) { // ... }); }});
// pages/pay/pay.js
Page({
/**
* 页面的初始数据
*/
data: {
},
payInput: function (e) {
console.log(e)
this.setData({
userN: e.detail.value
})
},
loginBtnClick: function () {
getApp().onLaunch(function (openid) {
var openid = JSON.stringify(openid.data)
wx.setStorageSync("openid",openid)
})
var openid = wx.getStorageSync('openid')
if (this.data.userN.length <= 0 ) {
this.setData({
infoMess: '温馨提示:请输入正确的金额!',
})
} else {
wx.request({
url: 'gong.90plus.cn/app/Pay/payfee', //你服务器code.php文件地址,默认GET。小程序只支持api.mch.weixin.qq.com/pay/unifiedorder';
$parameters = array(
'appid' => $appid, //小程序ID
'mch_id' => $mch_id, //商户号
'nonce_str' => $this->createNoncestr(), //随机字符串
// 'body' => 'test', //商品描述
'body' => $body,
// 'out_trade_no' => '2015450806125348', //商户订单号
'out_trade_no'=> $out_trade_no,
// 'total_fee' => floatval(0.01 * 100), //总金额 单位 分
'total_fee' => $total_fee,
// 'spbill_create_ip' => $_SERVER['REMOTE_ADDR'], //终端IP
'spbill_create_ip' => '116.62.121.247', //终端IP
'notify_url' => 'www.weixin.qq.com/wxpay/pay.php', //通知地址 确保外网能正常访问
'openid' =>$openid, //用户id
'trade_type' => 'JSAPI'//交易类型
);
//统一下单签名
$parameters['sign'] = $this->getSign($parameters);
$xmlData = $this->arrayToXml($parameters);
$return = $this->xmlToArray($this->postXmlCurl($xmlData, $url, 60));
return $return;
}
private function xmlToArray($xml) {
//禁止引用外部xml实体
libxml_disable_entity_loader(true);
$xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
$val = json_decode(json_encode($xmlstring), true);
return $val;
}
//数组转换成xml
private function arrayToXml($arr) {
$xml = "
本文共计533个文字,预计阅读时间需要3分钟。
小程序端页面初始化内容如下:javascriptPage({ data: { userN: '' }, payInput: function(e) { console.log(e); this.setData({ userN: e.detail.value }); }, loginBtnClick: function() { getApp().onLaunch(function(openid) { // ... }); }});
// pages/pay/pay.js
Page({
/**
* 页面的初始数据
*/
data: {
},
payInput: function (e) {
console.log(e)
this.setData({
userN: e.detail.value
})
},
loginBtnClick: function () {
getApp().onLaunch(function (openid) {
var openid = JSON.stringify(openid.data)
wx.setStorageSync("openid",openid)
})
var openid = wx.getStorageSync('openid')
if (this.data.userN.length <= 0 ) {
this.setData({
infoMess: '温馨提示:请输入正确的金额!',
})
} else {
wx.request({
url: 'gong.90plus.cn/app/Pay/payfee', //你服务器code.php文件地址,默认GET。小程序只支持api.mch.weixin.qq.com/pay/unifiedorder';
$parameters = array(
'appid' => $appid, //小程序ID
'mch_id' => $mch_id, //商户号
'nonce_str' => $this->createNoncestr(), //随机字符串
// 'body' => 'test', //商品描述
'body' => $body,
// 'out_trade_no' => '2015450806125348', //商户订单号
'out_trade_no'=> $out_trade_no,
// 'total_fee' => floatval(0.01 * 100), //总金额 单位 分
'total_fee' => $total_fee,
// 'spbill_create_ip' => $_SERVER['REMOTE_ADDR'], //终端IP
'spbill_create_ip' => '116.62.121.247', //终端IP
'notify_url' => 'www.weixin.qq.com/wxpay/pay.php', //通知地址 确保外网能正常访问
'openid' =>$openid, //用户id
'trade_type' => 'JSAPI'//交易类型
);
//统一下单签名
$parameters['sign'] = $this->getSign($parameters);
$xmlData = $this->arrayToXml($parameters);
$return = $this->xmlToArray($this->postXmlCurl($xmlData, $url, 60));
return $return;
}
private function xmlToArray($xml) {
//禁止引用外部xml实体
libxml_disable_entity_loader(true);
$xmlstring = simplexml_load_string($xml, 'SimpleXMLElement', LIBXML_NOCDATA);
$val = json_decode(json_encode($xmlstring), true);
return $val;
}
//数组转换成xml
private function arrayToXml($arr) {
$xml = "

