Prepay
POST
https://mapi.yuansfer.com/micropay/v3/prepay
This API does the mobile payment for the In-APP and/or WeChat Mini program solutions.
Request Body
The supported transaction currency is "USD", "CNY".
The supported settlement currency is "USD".
The possible payment channels are "alipay", "wechatpay".
The instant Payment Notification Handler URL. IPN URL must be secure.
openid from WeChat, which is only needed for the Wechat Mini-Program.
The Invoice Number of the transaction in the merchant's system.
The possible values are: "MINIPROGRAM", "APP".
The description of the transaction which will be displayed on the invoice.
The timeout in minutes.
The default value is 120.
{
"result": {
"nonceStr": "QyGptpsnpbydUzdVvkJy5fysWHYO48uF",
"package": "prepay_id=wx131236528509476a97469b574a5ea30000",
"paySign": "F2BB1584CB384DC008C665BD19FBB736BF24F1727CEB01159F9BEFA1162A61B7",
"signType": "HMAC-SHA256",
"timeStamp": "1602563859"
},
"ret_msg": " prepay success",
"ret_code": "000100"
}
Response
The wechat-mini result object.
The wechat-app result object.
The alipay-app result object.
The response return message.
The response return code. For more details, see here.
wehcat-mini result object
wechat-app result object
The value is 'Sign=WXPay'.
alipay-app result object
curl -XPOST -H "Content-type: application/json" -d '{
"merchantNo": "200043",
"storeNo": "300014",
"verifySign": "09f722178f6cf2e71c9dfdd664e8663b",
"amount": "10",
"currency": "CNY",
"settleCurrency": "USD",
"ipnUrl": "http://zk-tys.yunkeguan.com/login/test",
"reference": "test2020101302",
"description": "司机支付会员费用",
"vendor": "wechatpay",
"terminal": "MINIPROGRAM",
"openid": "ocBgh5fnabrf-pxPgCWXlq2mOvG8"
}' 'https://mapi.yuansfer.com/micropay/v3/prepay'
<?php
function microprepay()
{
$url = 'https://mapi.yuansfer.com/micropay/v3/prepay';
$token = '5cbfb079f15b150122261c8537086d77a';
$params = [
'merchantNo' => '200043',
'storeNo' => '300014',
'amount' => '0.01',
'currency' => 'USD',
'settleCurrency' => 'USD',
'vendor' => 'wechatpay',
'ipnUrl' => 'https://nengjtian.s1.natapp.cc/login/test',
'reference' => 'test2018070101',
'description' => 'test_description',
'note' => 'test_note',
'openid' => '***'
];
ksort($params, SORT_STRING);
$str = '';
foreach ($params as $k => $v) {
$str .= $k . '=' . $v . '&';
}
$params['verifySign'] = md5($str . md5($token));
echo 'verifySign:', $params['verifySign'];
echo "\n";
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HEADER => false,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => http_build_query($params),
));
$result = curl_exec($ch);
curl_exec($ch);
echo $result;
echo "\n";
return json_decode($result, true);
}
microprepay();
?>
public class MicropayTest {
public static final String TEST_URL = "https://mapi.yuansfer.yunkeguan.com"; //testing domain
public static final String PROD_URL = "https://mapi.yuansfer.com"; //production domain
public static final String YUANSFER_TOKEN = "5c5fe30183be69fceff8174358d4b8ae";
public static void main(String[] args) {
YuansferVerifySignHelper helper = new YuansferVerifySignHelper();
AppMircopayDto dto = paramSetting();
Map<String, Object> params = ReflectionUtils.convertBean2MapIgnoreNullVal(dto, new String[]{"serialVersionUID"});
String verifySign = helper.getYuansferVerifySign(params, YUANSFER_TOKEN);
params.put("verifySign", verifySign);
String url = TEST_URL + "/micropay/v2/prepay";
String ret = HttpClientUtils.post(url, null, params);
System.out.println(ret);
}
public static AppMircopayDto paramSetting() {
AppMircopayDto dto = new AppMircopayDto();
/**
* merchantNo,storeNo is necessory, and they are provided by Yuansfer
*/
dto.setMerchantNo("200043"); //The Merchant NO.
dto.setStoreNo("300014"); //The Store NO.
/**
* transaction infomation is necessory
*/
dto.setAmount("0.01"); //The amount, unit "division"
dto.setCurrency("USD"); //currency, "USD"
dto.setSettleCurrency("USD"); //SettleCurrency, "USD"
dto.setIpnUrl("https://nengjtian.s1.natapp.cc/login/test"); //Asynchronous callback address
dto.setReference("9091023122"); //order NO. of client's system
dto.setOpenid("***"); //wechat openid
dto.setVendor("wechatpay"); //"wechatpay"
/**
* note,desription are optional
*/
dto.setDescription("test-description"); //description
dto.setNote("test-note"); //note
return dto;
}
}
func mciropay(t *table) {
req := yuan.Securepay{
MerchantNo: "200043", //customer The merchant NO.
StoreNo: "300014",
Currency: "USD",
SettleCurrency: "USD",
Amount: "0.01",
Vendor: "wechatpay",
Reference: fmt.Sprintf("demo_%d", time.Now().Unix()), //sequence number of customer system
IpnUrl: "https://customer-ipn", //internet accessible
Description: "description",
Note: "note",
Openid: "***",
}
resp, err := req.PostToYuansfer(yuansferToken)
if err != nil {
fmt.Println(err)
return
}
fmt.Println(resp)
}