<commit_before>import xml2js from 'xml2js';
import request from 'request';
import Common from './common';
import Config from '../config';

const queryString = require('query-string');

export default class OrderTrace extends Common {
    /**
     * @description search order route
     * @params tracking_type(订单类型 1: 顺丰运单号 2: 客户订单号 默认为1)
     *         tracking_number(订单号)
     *         method_type(路由查询类别 1: 标准路由查询 2: 定制路由查询)
     * @example
     *  { tracking_type: 1, tracking_number: '444003077898' }
     */
    // super props
    constructor(props) {
        super(props);
    }
    // getStr
    /** request infomation
     * <Request service='RouteService' lang='zh-CN'>
        <Head>BSPdevelop</Head>
        <Body>
            <RouteRequest
            tracking_type='1'
            method_type='1'
            tracking_number='444003077898'/>
        </Body>
        </Request>
     */
    buildNowXml(data) {
        const xml = `<Request service='RouteService' lang='zh-CN'>
                        <Head>${this.options.devCode},${this.options.checkword}</Head>
                        <Body>${data}</Body>
                     </Request>`;
        return xml;
    }
    getStr(data) {
        let order = '<RouteRequest ';
        for (const item in data) {
            order = `${order}${item}="${data[item]}" `;
        }
        order = order + '/>';
        const xml = this.buildNowXml(order);
        const sign = this._getSign(xml, this.options.checkword);
        return queryString.stringify({ xml, verifyCode: sign });
    }
    //sendOrderTraceRequest
    sendOrderTraceRequest(data) {
        const url = this.options.url;
        const  formData = this.getStr(data);
        return new Promise((resolve, reject) => {
            request({
                headers: {
                    'charset': 'UTF-8',
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                uri: url,
                body: formData,
                method: 'POST'
            }, function (err, res, body) {
                if(err) {
                    reject(err);
                } else {
                    console.log(body);
                    const parser = new xml2js.Parser({ trim: true, explicitArray: false, explicitRoot: false });
                    parser.parseString(body, (error, result) => {
                        console.log(result);
                        if (result.Head === 'OK') {
                            const obj = result.Body.RouteResponse.$;
                            resolve(obj);
                        } else {
                            const obj = { message: 'ERR' };
                            obj.result = result;
                            resolve(obj);
                        }
                    });
                }
            });
        });
    }
    // make order trace
    makeOrderTrace(requestData, options = {}) {
        this.mixOptions(Config.sfOrderTrace, options);
        return this.sendOrderTraceRequest(requestData);
    }
}<commit_msg>[dev]update orderTrace result<commit_after>import xml2js from 'xml2js';
import request from 'request';
import Common from './common';
import Config from '../config';

const queryString = require('query-string');

export default class OrderTrace extends Common {
    /**
     * @description search order route
     * @params tracking_type(订单类型 1: 顺丰运单号 2: 客户订单号 默认为1)
     *         tracking_number(订单号)
     *         method_type(路由查询类别 1: 标准路由查询 2: 定制路由查询)
     * @example
     *  { tracking_type: 1, tracking_number: '444003077898' }
     */
    // super props
    constructor(props) {
        super(props);
    }
    // getStr
    /** request infomation
     * <Request service='RouteService' lang='zh-CN'>
        <Head>BSPdevelop</Head>
        <Body>
            <RouteRequest
            tracking_type='1'
            method_type='1'
            tracking_number='444003077898'/>
        </Body>
        </Request>
     */
    buildNowXml(data) {
        const xml = `<Request service='RouteService' lang='zh-CN'>
                        <Head>${this.options.devCode},${this.options.checkword}</Head>
                        <Body>${data}</Body>
                     </Request>`;
        return xml;
    }
    getStr(data) {
        let order = '<RouteRequest ';
        for (const item in data) {
            order = `${order}${item}="${data[item]}" `;
        }
        order = order + '/>';
        const xml = this.buildNowXml(order);
        const sign = this._getSign(xml, this.options.checkword);
        return queryString.stringify({ xml, verifyCode: sign });
    }
    //sendOrderTraceRequest
    sendOrderTraceRequest(data) {
        const url = this.options.url;
        const  formData = this.getStr(data);
        return new Promise((resolve, reject) => {
            request({
                headers: {
                    'charset': 'UTF-8',
                    'Content-Type': 'application/x-www-form-urlencoded'
                },
                uri: url,
                body: formData,
                method: 'POST'
            }, function (err, res, body) {
                if(err) {
                    reject(err);
                } else {
                    console.log(body);
                    const parser = new xml2js.Parser({ trim: true, explicitArray: false, explicitRoot: false });
                    parser.parseString(body, (error, result) => {
                        console.log(result);
                        if (result.Head === 'OK') {
                            const obj = {};
                            obj.mailno = result.Body.RouteResponse.$.mailno;
                            obj.trace = result.Body.RouteResponse.Route;
                            resolve(obj);
                        } else {
                            const obj = { message: 'ERR' };
                            obj.result = result;
                            resolve(obj);
                        }
                    });
                }
            });
        });
    }
    // make order trace
    makeOrderTrace(requestData, options = {}) {
        this.mixOptions(Config.sfOrderTrace, options);
        return this.sendOrderTraceRequest(requestData);
    }
}
{'fraction_non_alphanumeric': 0.12210324436630973, 'fraction_numerical': 0.011507112034521335, 'mean_word_length': 1.4171494785631518, 'pattern_counts': {'":': 0, '<': 31, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7291518', 'n_tokens_mistral': 1757, 'n_tokens_neox': 1700, 'n_words': 347}